Arduino HelloWorld

I Started programming a hello World program to an Arduino UNO on a xubuntu 12.04 beta1 with a program called arduino 1.0 as a part of a course at Haaga-Helia held by Tero Karvinen: http://terokarvinen.com/2012/aikataulu-prototyypin-rakentaminen-bus4tn007-1

I decided to do a program which could translate all the letters to morse code:


void setup()
{
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
}

void loop()
{
H();
I();
}

void shortBlink()
{
digitalWrite(13, HIGH);//led on
delay(250);//time before moving to next line of code (ms - milli second)
digitalWrite(13, LOW);//led off
delay(50);
}

void longBlink()
{
digitalWrite(13, HIGH);
delay(750);
digitalWrite(13, LOW);
delay(100);
}

void A()
{
shortBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void B()
{
longBlink();
shortBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void C()
{
longBlink();
shortBlink();
longBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void D()
{
longBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void E()
{
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void F()
{
shortBlink();
shortBlink();longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void G()
{
longBlink();
longBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void H()
{
shortBlink();
shortBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void I()
{
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

As you can see it’s still a work in progress. But what caught me by surprise was that when I installed Arduino 1.0 on my windows 7 and tried to execute the code I got the following errors:


sketch_mar30c:-1: error: expected unqualified-id before 'reinterpret_cast'
sketch_mar30c:-1: error: expected `)' before 'reinterpret_cast'
sketch_mar30c:-1: error: expected unqualified-id before ')' token
sketch_mar30c:74: error: expected unqualified-id before 'reinterpret_cast'
sketch_mar30c:74: error: expected `)' before 'reinterpret_cast'
sketch_mar30c:74: error: expected unqualified-id before ')' token

I first tried to run the code through notepad to see if there was any problems with fonts or other extra what doesn’t belong there. it didn’t fix my problem.

Next I tried to check the code for errors, no luck.

I opened the blink example to see if the syntax was different for some weird reason, the example worked fine even with my modifications similar to the original file I was trying to fix.

So lastly I decided to cut my code from the end so I could find my error:


void setup()
{
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
}

void loop()
{
H();
I();
}

void shortBlink()
{
digitalWrite(13, HIGH);//led on
delay(250);//time before moving to next line of code (ms - milli second)
digitalWrite(13, LOW);//led off
delay(50);
}

void longBlink()
{
digitalWrite(13, HIGH);
delay(750);
digitalWrite(13, LOW);
delay(100);
}

void A()
{
shortBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void B()
{
longBlink();
shortBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void C()
{
longBlink();
shortBlink();
longBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

The program didn’t show any errors, finally some progress! After adding the following code:


void D()
{
longBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void E()
{
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void F()
{
shortBlink();
shortBlink();longBlink();
digitalWrite(13, LOW);
delay(1000);
}

The error returned. I pinpointed the problem to be on


void F()
{
shortBlink();
shortBlink();longBlink();
digitalWrite(13, LOW);
delay(1000);
}

and finally decided to test to change void F() to something else. It worked again!

I have no idea what the problem could be and why I  couldn’t use “F” but “f” worked fine. I’ll have to double check if this problem was only on the Windows version and not on the Linux one. The problem was found on both operating systems

EDIT:

The finished code:


void setup()
{
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
}
//http://en.wikipedia.org/wiki/Morse_code
void loop()
{
digitalWrite(12, HIGH);//RED
delay(1);
digitalWrite(11, HIGH);//GREEN
delay(1);
//REST IN YELLOW, THE ACTIUAL PROGRAM
a();
r();
d();
u();
i();
n();
o();
}

void shortBlink()
{
digitalWrite(13, HIGH);//led on
delay(250);//time before moving to next line of code (ms - milli second)
digitalWrite(13, LOW);//led off
delay(50);
}

void longBlink()
{
digitalWrite(13, HIGH);
delay(750);
digitalWrite(13, LOW);
delay(100);
}

void a()
{
shortBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void b()
{
longBlink();
shortBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void c()
{
longBlink();
shortBlink();
longBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void d()
{
longBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void e()
{
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void f()
{
shortBlink();
shortBlink();longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void g()
{
longBlink();
longBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void h()
{
shortBlink();
shortBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void i()
{
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void j()
{
shortBlink();
longBlink();
longBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void k()
{
longBlink();
shortBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void l()
{
shortBlink();
longBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void m()
{
longBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void n()
{
longBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void o()
{
longBlink();
longBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void p()
{
shortBlink();
longBlink();
longBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void q()
{
longBlink();
longBlink();
shortBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void r()
{
shortBlink();
longBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void s()
{
shortBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void t()
{
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void u()
{
shortBlink();
shortBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void v()
{
shortBlink();
shortBlink();
shortBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void w()
{
shortBlink();
longBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void x()
{
longBlink();
shortBlink();
shortBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void y()
{
longBlink();
shortBlink();
longBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void z()
{
longBlink();
longBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void zero()
{
longBlink();
longBlink();
longBlink();
longBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void one()
{
shortBlink();
longBlink();
longBlink();
longBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void two()
{
shortBlink();
shortBlink();
longBlink();
longBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void three()
{
shortBlink();
shortBlink();
shortBlink();
longBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void four()
{
shortBlink();
shortBlink();
shortBlink();
shortBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void five()
{
shortBlink();
shortBlink();
shortBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void six()
{
longBlink();
shortBlink();
shortBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void seven()
{
longBlink();
longBlink();
shortBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void eight()
{
longBlink();
longBlink();
longBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void nine()
{
longBlink();
longBlink();
longBlink();
longBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

Arduino Uno working

The program working:

How the wiring was done:

I placed the black wire on the gnd (ground), yellow on 13, grey on 12 and green on 11.

the red led uses the grey and black wire

the yellow led uses the yellow and black wire

the green led uses the green and black wire

Advertisements

One thought on “Arduino HelloWorld

  1. Thank you for posting this. I was making a related program and having the same problem. I changed my file name from ‘F’ to ‘capF’ and it solved the problem. Really weird but now I can move on.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s