Go to Post "Evaluate twice, execute once" - Andrew Schreiber [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rating: Thread Rating: 3 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 19-02-2014, 14:33
adlasa's Avatar
adlasa adlasa is offline
President and Lead Programmer
AKA: Sasha
FRC #1458 (Red Ties)
Team Role: Leadership
 
Join Date: Dec 2012
Rookie Year: 2011
Location: Bay Area
Posts: 35
adlasa has a spectacular aura aboutadlasa has a spectacular aura aboutadlasa has a spectacular aura about
Morse Code

Hello guys. I wrote a Morse Code class which takes a solenoid which powers our camera light, and a text to convert to Morse. It runs on a parallel thread and allows the camera to flash some fun and interesting messages.

Hope you like it,
Sasha

Code:
public class MorseCode implements Runnable{

	//To Call: (new Thread(new MorseCode("Hello World", caneraLight)).start();

	public static String sentance;
	public static String code[];
	public static Solenoid cameraLight;
	public static boolean isDone;

	public MorseCode(String inputSentance, Solenoid light){
		code = new String[inputSentance.length()];
		sentance = inputSentance;
		cameraLight = light;
		convertToMorse();
		isDone = false;
	}
	public void run(){
		cameraLight.set(false);
		try {
			Thread.sleep(4200);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		for(int i = 0; i < code.length; i++){
			for(int j = 0; j < code[i].length(); j++){
				if(code[i].charAt(j) == '*'){
					cameraLight.set(true);
					try {
						Thread.sleep(600);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}else if(code[i].charAt(j) == '-'){
					cameraLight.set(true);
					try {
						Thread.sleep(1800);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}else if(code[i].charAt(j) == ' '){
					cameraLight.set(false);
					try {
						Thread.sleep(600);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
			cameraLight.set(false);
			try {
				Thread.sleep(1800);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		isDone = true;
	}
	private void convertToMorse(){
		for(int i = 0; i < sentance.length(); i++){
			if(sentance.charAt(i)=='A' || sentance.charAt(i)=='a')
				code[i] = "* -";
			else if(sentance.charAt(i)=='B' || sentance.charAt(i)=='b')
				code[i] = "- * * *";
			else if(sentance.charAt(i)=='C' || sentance.charAt(i)=='c')
				code[i] = "- * - *";
			else if(sentance.charAt(i)=='D' || sentance.charAt(i)=='d')
				code[i] = "- * *";
			else if(sentance.charAt(i)=='E' || sentance.charAt(i)=='e')
				code[i] = "*";
			else if(sentance.charAt(i)=='F' || sentance.charAt(i)=='f')
				code[i] = "* * - *";
			else if(sentance.charAt(i)=='G' || sentance.charAt(i)=='g')
				code[i] = "- - *";
			else if(sentance.charAt(i)=='H' || sentance.charAt(i)=='h')
				code[i] = "* * * *";
			else if(sentance.charAt(i)=='I' || sentance.charAt(i)=='i')
				code[i] = "* *";
			else if(sentance.charAt(i)=='J' || sentance.charAt(i)=='j')
				code[i] = "* - - -";
			else if(sentance.charAt(i)=='K' || sentance.charAt(i)=='k')
				code[i] = "- * -";
			else if(sentance.charAt(i)=='L' || sentance.charAt(i)=='l')
				code[i] = "* - * *";
			else if(sentance.charAt(i)=='M' || sentance.charAt(i)=='m')
				code[i] = "- -";
			else if(sentance.charAt(i)=='N' || sentance.charAt(i)=='n')
				code[i] = "- *";
			else if(sentance.charAt(i)=='O' || sentance.charAt(i)=='o')
				code[i] = "- - -";
			else if(sentance.charAt(i)=='P' || sentance.charAt(i)=='p')
				code[i] = "* - - *";
			else if(sentance.charAt(i)=='Q' || sentance.charAt(i)=='q')
				code[i] = "- - * -";
			else if(sentance.charAt(i)=='R' || sentance.charAt(i)=='r')
				code[i] = "* - *";
			else if(sentance.charAt(i)=='S' || sentance.charAt(i)=='s')
				code[i] = "* * *";
			else if(sentance.charAt(i)=='T' || sentance.charAt(i)=='t')
				code[i] = "-";
			else if(sentance.charAt(i)=='U' || sentance.charAt(i)=='u')
				code[i] = "* * -";
			else if(sentance.charAt(i)=='V' || sentance.charAt(i)=='v')
				code[i] = "* * * -";
			else if(sentance.charAt(i)=='W' || sentance.charAt(i)=='w')
				code[i] = "* - -";
			else if(sentance.charAt(i)=='X' || sentance.charAt(i)=='x')
				code[i] = "- * * -";
			else if(sentance.charAt(i)=='Y' || sentance.charAt(i)=='y')
				code[i] = "- * - -";
			else if(sentance.charAt(i)=='Z' || sentance.charAt(i)=='z')
				code[i] = "- - * *";
			else if(sentance.charAt(i)=='0')
				code[i] = "- - - - -";
			else if(sentance.charAt(i)=='1')
				code[i] = "* - - - -";
			else if(sentance.charAt(i)=='2')
				code[i] = "* * - - -";
			else if(sentance.charAt(i)=='3')
				code[i] = "* * * - -";
			else if(sentance.charAt(i)=='4')
				code[i] = "* * * * -";
			else if(sentance.charAt(i)=='5')
				code[i] = "* * * * *";
			else if(sentance.charAt(i)=='6')
				code[i] = "- * * * *";
			else if(sentance.charAt(i)=='7')
				code[i] = "- - * * *";
			else if(sentance.charAt(i)=='8')
				code[i] = "- - - * *";
			else if(sentance.charAt(i)=='9')
				code[i] = "- - - - *";
			else
				code[i] = " ";
		}
	}
}
__________________
Computers run on smoke. When the smoke escapes the computers stop working.
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 03:51.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi