the_ledtester_class
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
the_ledtester_class [2018/08/11 01:00] – frchris | the_ledtester_class [2018/08/11 01:07] – frchris | ||
---|---|---|---|
Line 10: | Line 10: | ||
public class LEDTester | public class LEDTester | ||
{ | { | ||
- | public LED pin1; | + | |
| | ||
//unit of time, in milliseconds | //unit of time, in milliseconds | ||
Line 19: | Line 19: | ||
| | ||
String s = "SOS SOS SOS"; | String s = "SOS SOS SOS"; | ||
- | | + | |
- | | + | |
s = args[0]; | s = args[0]; | ||
- | | + | |
lt.flashMorse(s); | lt.flashMorse(s); | ||
lt.finalize(); | lt.finalize(); | ||
} | } | ||
+ | | ||
/* | /* | ||
* create a new LED instance | * create a new LED instance | ||
Line 39: | Line 39: | ||
pin1 = p; | pin1 = p; | ||
} | } | ||
- | + | | |
/* | /* | ||
* Flashes the LED 10 times | * Flashes the LED 10 times | ||
*/ | */ | ||
public void flash10Times() { | public void flash10Times() { | ||
- | for(int i = 0; i < 10; i++) { | + | |
+ | | ||
pin1.flash(200); | pin1.flash(200); | ||
- | try { Thread.sleep200; } catch (InterruptedException e) {} | + | try { Thread.sleep (200); } catch (InterruptedException e) {} |
} | } | ||
} | } | ||
+ | | ||
+ | | ||
/* | /* | ||
- | | + | |
*/ | */ | ||
- | public | + | public |
- | | + | |
+ | | ||
+ | |||
+ | // . = 1, - = 3, intra-char = 1, inter-char = 3, space = 7.", | ||
+ | |||
+ | for (char atom : morse) { | ||
+ | if (atom == ' | ||
+ | pin1.flash(UNIT); | ||
+ | } else if (atom == ' | ||
+ | pin1.flash(3*UNIT); | ||
+ | } else if (atom == '/' | ||
+ | sleep (1); // plus one leading and one trailing == 3 | ||
+ | } else { | ||
+ | // must be a space | ||
+ | sleep (5); // plus one leading and one trailing == 7 | ||
+ | } | ||
+ | sleep (1); // common gap | ||
+ | } | ||
+ | } | ||
+ | /* | ||
+ | * Wait units times the defined unit of time | ||
+ | */ | ||
+ | private void sleep(int units) { | ||
+ | try { | ||
+ | Thread.sleep(units*UNIT); | ||
+ | } catch (InterruptedException e) | ||
+ | { | ||
+ | } | ||
} | } | ||
protected void finalize(){ | protected void finalize(){ | ||
pin1.finalize(); | pin1.finalize(); | ||
- | } | + | } |
} | } | ||
</ | </ | ||
the_ledtester_class.txt · Last modified: 2018/08/11 01:10 by frchris