using System; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.Netduino; namespace NetduinoApplication1 { public class Program { public static void Main() { // write your code here OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); sayhello sho = new sayhello(); while (true) { sho.dosayhello(led); } } } public class sayhello { private const int dittime = 100; private const int dahtime = dittime*3; private const int intersymtime = dittime * 1; private const int interchartime = dittime * 5; private const int interwordtime = dittime * 10; public void dosayhello(OutputPort led) { doWord(led, "HELLO"); doWord(led, "from"); doWord(led, "Greg"); } public void doWord(OutputPort led, string ss) { ss = ss.ToLower(); foreach (char cc in ss) { switch (cc) { case 'a': a(led); break; case 'b': b(led); break; case 'c': c(led); break; case 'd': d(led); break; case 'e': e(led); break; case 'f': f(led); break; case 'g': g(led); break; case 'h': h(led); break; case 'i': i(led); break; case 'j': j(led); break; case 'k': k(led); break; case 'l': l(led); break; case 'm': m(led); break; case 'n': n(led); break; case 'o': o(led); break; case 'p': p(led); break; case 'q': q(led); break; case 'r': r(led); break; case 's': s(led); break; case 't': t(led); break; case 'u': u(led); break; case 'v': v(led); break; case 'w': w(led); break; case 'x': x(led); break; case 'y': y(led); break; case 'z': z(led); break; case ' ': Thread.Sleep(interwordtime); break; } } Thread.Sleep(interwordtime); } private void a(OutputPort led) { dit(led); dah(led); Thread.Sleep(interchartime); } private void b(OutputPort led) { dah(led); dit(led); dit(led); dit(led); Thread.Sleep(interchartime); } private void c(OutputPort led) { dah(led); dit(led); dah(led); dit(led); Thread.Sleep(interchartime); } private void d(OutputPort led) { dah(led); dit(led); dit(led); Thread.Sleep(interchartime); } private void e(OutputPort led) { dit(led); Thread.Sleep(interchartime); } private void f(OutputPort led) { dit(led); dit(led); dah(led); dit(led); Thread.Sleep(interchartime); } private void g(OutputPort led) { dah(led); dah(led); dit(led); Thread.Sleep(interchartime); } private void h(OutputPort led) { dit(led); dit(led); dit(led); dit(led); Thread.Sleep(interchartime); } private void i(OutputPort led) { dit(led); dit(led); Thread.Sleep(interchartime); } private void j(OutputPort led) { dit(led); dah(led); dah(led); dah(led); Thread.Sleep(interchartime); } private void k(OutputPort led) { dah(led); dit(led); dah(led); Thread.Sleep(interchartime); } private void l(OutputPort led) { dit(led); dah(led); dit(led); dit(led); Thread.Sleep(interchartime); } private void m(OutputPort led) { dah(led); dah(led); Thread.Sleep(interchartime); } private void n(OutputPort led) { dah(led); dit(led); Thread.Sleep(interchartime); } private void o(OutputPort led) { dah(led); dah(led); dah(led); Thread.Sleep(interchartime); } private void p(OutputPort led) { dah(led); dah(led); dah(led); dah(led); Thread.Sleep(interchartime); } private void q(OutputPort led) { dah(led); dah(led); dit(led); dah(led); Thread.Sleep(interchartime); } private void r(OutputPort led) { dit(led); dah(led); dit(led); Thread.Sleep(interchartime); } private void s(OutputPort led) { dit(led); dit(led); dit(led); Thread.Sleep(interchartime); } private void t(OutputPort led) { dah(led); Thread.Sleep(interchartime); } private void u(OutputPort led) { dit(led); dit(led); dah(led); Thread.Sleep(interchartime); } private void v(OutputPort led) { dit(led); dit(led); dit(led); dah(led); Thread.Sleep(interchartime); } private void w(OutputPort led) { dit(led); dah(led); dah(led); Thread.Sleep(interchartime); } private void x(OutputPort led) { dah(led); dit(led); dit(led); dah(led); Thread.Sleep(interchartime); } private void y(OutputPort led) { dah(led); dit(led); dah(led); dah(led); Thread.Sleep(interchartime); } private void z(OutputPort led) { dah(led); dah(led); dit(led); dit(led); Thread.Sleep(interchartime); } private void dit(OutputPort led) { led.Write(true); Thread.Sleep(dittime); led.Write(false); Thread.Sleep(intersymtime); } private void dah(OutputPort led) { led.Write(true); Thread.Sleep(dahtime); led.Write(false); Thread.Sleep(intersymtime); } } }

Simple Blinking LED Morse Code
#1
Posted 30 September 2010 - 12:50 PM
#2
Posted 30 September 2010 - 01:20 PM
#3
Posted 30 September 2010 - 02:18 PM
#4
Posted 01 October 2010 - 01:21 PM
Nice. IMHO using a lookup table would significantly increase readability and simplify the code - something like Scott Hanselman's sample (code is in the middle of the page, just above comments).
If I had seen Scott's post I wouldn't have bothered to post mine. Scott's code is smaller, thats true, but in my defence I will say that because of cut and paste I bet mine took less time to write.
Next time I will try to add something more interesting.
#5
Posted 01 October 2010 - 01:58 PM
I hope you continue to share. It's not about code efficiency, it's about sharing our excitement about the Netduino. I think it is just incredibly fun to be able to use Intellisense, and single-step through code that is running on that little board.If I had seen Scott's post I wouldn't have bothered to post mine. Scott's code is smaller, thats true, but in my defence I will say that because of cut and paste I bet mine took less time to write.
Next time I will try to add something more interesting.
#6
Posted 01 October 2010 - 03:22 PM
I am sorry for any inconvenience, there is no need to defend yourself - please consider my comment as a fellow developer code review adviceIf I had seen Scott's post I wouldn't have bothered to post mine. Scott's code is smaller, thats true, but in my defence...

#7
Posted 01 October 2010 - 04:55 PM
... it's about sharing our excitement about the Netduino. ...
And your code worked fine first time, blinking the led as it should be. In the end it is Morse ... dit dah sound or light

The "other" code is no 100.00% correct ... it does not blink the led correctly.
At bottom the code
port.Write(true);
if (dotordash == '.')
Thread.Sleep(100); //dot
else
Thread.Sleep(300); //dash
port.Write(false);
needs one more
Thread.Sleep(100);
to blink "MORSEish"

Keep posting your code

Regards
#8
Posted 02 October 2010 - 06:11 AM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users