Flashing Hazard LED's

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
jasiu
 
Posts: 35
Joined: Mon Oct 14, 2013 1:47 pm

Re: Flashing Hazard LED's

Post by jasiu »

Ok, so after some putzing around I came up with the following:

Code: Select all

// LED's connected to pins 9,10,11
int redPin=9;
int bluePin = 10;
int greenPin=11;
// run once, when the sketch starts
void setup() 
{
// sets the digital pin as output
pinMode(redPin, OUTPUT); 
pinMode(bluePin,OUTPUT);
pinMode(greenPin, OUTPUT);
}

// run over and over again 
void loop() 
{
// 3 dits, 3 dahs, 3 dits
for (int x=0; x<3; x++) 
{
analogWrite(redPin, 255); // max intensity red
analogWrite(greenPin, 127) // half intensity green
delay(100); // waits for 100ms
analogWrite(redPin, 0); // off
analogWrite(greenPin, 0) // off
delay(300); // waits for 100ms
}
}

// 100ms delay to cause slight gap between letters
delay(100); 
// 3 dahs
for (int x=0; x<3; x++) {
for (int x=0; x<3; x++) 
{
analogWrite(redPin, 255); // max intensity red
analogWrite(greenPin, 127) // half intensity green
delay(300); // waits for 300ms
analogWrite(redPin, 0); // off
analogWrite(greenPin, 0) // off
delay(100); // waits for 100ms
}waits for 100ms
// wait 3 seconds before repeating the SOS signal 
delay(3000); 
}
I tried to Verify but apparently I messed up and it gives me a bunch of error messages. The error messages are rather cryptic, at least for me.

I tried copying the error messages but it wouldn't let me.
Last edited by adafruit_support_bill on Sun Aug 31, 2014 9:48 am, edited 1 time in total.
Reason: please use the </> button when submitting code. press </>, then paste your code between the [code] [/code] tags.

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: Flashing Hazard LED's

Post by adafruit_support_bill »

1 - you need to terminate each statement with a semicolon ';'. You have several 'analogWrite()' statements that are missing semicolons.

2 - you need to pay attention to your brackets. They define the 'scope' of a function, and fFor every "{" you need to have a matching "}". In this case, you have the loop function:

Code: Select all

// run over and over again 
void loop() 
{
// 3 dits, 3 dahs, 3 dits
for (int x=0; x<3; x++) 
{
analogWrite(redPin, 255); // max intensity red
analogWrite(greenPin, 127); // half intensity green
delay(100); // waits for 100ms
analogWrite(redPin, 0); // off
analogWrite(greenPin, 0); // off
delay(300); // waits for 100ms
}
}
and then a bunch of code after that.

Code: Select all


// 100ms delay to cause slight gap between letters
delay(100); 
// 3 dahs
for (int x=0; x<3; x++) {
for (int x=0; x<3; x++) 
{
analogWrite(redPin, 255); // max intensity red
analogWrite(greenPin, 127) // half intensity green
delay(300); // waits for 300ms
analogWrite(redPin, 0); // off
analogWrite(greenPin, 0) // off
delay(100); // waits for 100ms
}waits for 100ms
// wait 3 seconds before repeating the SOS signal 
delay(3000); 
}
Since that code is not within the loop function brackets, the compiler doesn't know what to do with it.

It helps if you indent your code consistently so that you can see when the brackets are 'unbalanced'.

You also have an incomplete 'for' loop here:

Code: Select all

// 100ms delay to cause slight gap between letters
delay(100); 
// 3 dahs
for (int x=0; x<3; x++) {
for (int x=0; x<3; x++) 
{

User avatar
jasiu
 
Posts: 35
Joined: Mon Oct 14, 2013 1:47 pm

Re: Flashing Hazard LED's

Post by jasiu »

Thank you sir

User avatar
jasiu
 
Posts: 35
Joined: Mon Oct 14, 2013 1:47 pm

Re: Flashing Hazard LED's

Post by jasiu »

So I wired everything up per the diagram, verified the code I wrote, downloaded the code and............. absolutely nothing happened. Here is my code, I am trying to flash SOS in Morse Code on a strip of analog lights

Code: Select all

//LED Red=256, Green=127, Blue=0
int Pin_LED_Red=3;
int Pin_LED_Green=5;
int Pin_LED_Blue=6;
void setup() {
  // set mode of pins as outputs to run once
  pinMode(Pin_LED_Red,OUTPUT);
  pinMode(Pin_LED_Green,OUTPUT);
  pinMode(Pin_LED_Blue,OUTPUT);


}

void loop() {
  // 3 Dits
  for(int x=0;x<<3;x+1);
  analogWrite(Pin_LED_Red,255); // Mav intensity of red;
  analogWrite(Pin_LED_Green,128); // Half intensity of Green;
  analogWrite(Pin_LED_Blue,0); //No Blue because Red and Green make Orange
  delay(100); //DelaayON tine 100 ms
  // 3 Dahs
  analogWrite(Pin_LED_Red,0);
  analogWrite(Pin_LED_Green,0);
  analogWrite(Pin_LED_Blue,0); 
  delay(300);
Last edited by adafruit_support_bill on Fri Sep 19, 2014 12:03 pm, edited 1 time in total.
Reason: please use the </> button when submitting code. press </>, then paste your code between the [code] [/code] tags.

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: Flashing Hazard LED's

Post by adafruit_support_bill »

Post photos showing all of your connections.

User avatar
jasiu
 
Posts: 35
Joined: Mon Oct 14, 2013 1:47 pm

Re: Flashing Hazard LED's

Post by jasiu »

photo 2 (1).JPG
photo 2 (1).JPG (121.93 KiB) Viewed 236 times
photo 1 (1).JPG
photo 1 (1).JPG (159.25 KiB) Viewed 236 times
Ok, here goes

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: Flashing Hazard LED's

Post by adafruit_support_bill »

I can't see in your photos. Is there a common ground between the Arduino and the LED power supply?

User avatar
jasiu
 
Posts: 35
Joined: Mon Oct 14, 2013 1:47 pm

Re: Flashing Hazard LED's

Post by jasiu »

I have a 12 Volt battery and the negative of that battery goes to the negative rail of the breadboard which in turn goes to the Arduino. Im thinkinh the problem may be that the clip connector isnt passing voltage

User avatar
jasiu
 
Posts: 35
Joined: Mon Oct 14, 2013 1:47 pm

Re: Flashing Hazard LED's

Post by jasiu »

So success, sort of. I got it to flash light, but not the way I want them to

User avatar
jasiu
 
Posts: 35
Joined: Mon Oct 14, 2013 1:47 pm

Re: Flashing Hazard LED's

Post by jasiu »

So it flashes, just not in Morse code

User avatar
jasiu
 
Posts: 35
Joined: Mon Oct 14, 2013 1:47 pm

Re: Flashing Hazard LED's

Post by jasiu »

So can someone help me where I went wrong? Attached is the sketch I've written to blink SOS. Only trouble is that it doesn't blink SOS. Just two blinks followed by a pause then repeats

//LED Red=256, Green=127, Blue=0, Red and Green make Orange
int Pin_LED_Red=3;
int Pin_LED_Green=5;
int Pin_LED_Blue=6;
void setup() {
// set mode of pins as outputs to run once
pinMode(Pin_LED_Red,OUTPUT);
pinMode(Pin_LED_Green,OUTPUT);
pinMode(Pin_LED_Blue,OUTPUT);


}

void loop() {
// 3 Dits
for(int x=0;x<3;x++);
analogWrite(Pin_LED_Red,250); // Mav intensity of red;
analogWrite(Pin_LED_Green,125); // Half intensity of Green;
analogWrite(Pin_LED_Blue,0); //No Blue because Red and Green make Orange
delay(100); //DelaayON tine 100 ms

// Off for 200 ms
analogWrite(Pin_LED_Red,0);
analogWrite(Pin_LED_Green,0);
analogWrite(Pin_LED_Blue,0);
delay(200);
// 3 Dahs
for(int x=0;x<3;x++);
analogWrite(Pin_LED_Red,250); // Mav intensity of red;
analogWrite(Pin_LED_Green,125); // Half intensity of Green;
analogWrite(Pin_LED_Blue,0); //No Blue because Red and Green make Orange
delay(600); //DelaayON tine 300 ms

// Off for 200 ms
analogWrite(Pin_LED_Red,0);
analogWrite(Pin_LED_Green,0);
analogWrite(Pin_LED_Blue,0);
delay(200);

// 3 Dits
for(int x=0;x<3;x++);
analogWrite(Pin_LED_Red,255); // Mav intensity of red;
analogWrite(Pin_LED_Green,128); // Half intensity of Green;
analogWrite(Pin_LED_Blue,0); //No Blue because Red and Green make Orange
delay(100); //DelaayON tine 100 ms

}>

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: Flashing Hazard LED's

Post by adafruit_support_bill »

Your problem is the semicolon at the end of the 'for' statement:

Code: Select all

for(int x=0;x<3;x++);
That terminates the statement without doing anything. If you have multiple statements in your 'for' loop, you need to enclose them in brackets like this:

Code: Select all

for(int x=0;x<3;x++)
{
   analogWrite(Pin_LED_Red,250); // Mav intensity of red;
   analogWrite(Pin_LED_Green,125); // Half intensity of Green;
   analogWrite(Pin_LED_Blue,0); //No Blue because Red and Green make Orange
   delay(100); //DelaayON tine 100 ms

   // Off for 200 ms
    analogWrite(Pin_LED_Red,0);
   analogWrite(Pin_LED_Green,0);
   analogWrite(Pin_LED_Blue,0); 
   delay(200);
}

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”