I have some level of programming background, however never with Arduino's. I've just started hacking at the examples - I'm not even sure what language I'm currently writing. I presume it's C++.
Anyway, I figured I'd try out the pin 13 LED with the BlinkWithoutDelay example. I've got that running fine (which I was very excited about), however I've tried to modify it to blink out SOS in Morse code, but it doesn't appear to be working.
// constants won't change. Used here to set a pin number :
const int ledPin = 13; // the number of the LED pin
// Variables will change :
int ledState = LOW; // ledState used to set the LED
// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0; // will store last time LED was updated
// constants won't change :
//unsigned long interval = 1000; // interval at which to blink (milliseconds)
// Number of times to blink
const long blinkMax = 10;
// Counter for number of times blinked
unsigned long blinkCount = 0;
void setup() {
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
}
void loop()
{
int loopCount = 0;
// S O S
int values[] = {1000, 1000, 1000, 200, 200, 200, 1000, 1000, 100};
blink(values[loopCount]);
loopCount = loopCount + 1;
}
void blink(int interval)
{
unsigned long currentMillis = millis();
if(currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
digitalWrite(ledPin, ledState);
}
}
As you can see, I've assigned the time values (1000 for long and 200 for short) to an array and had the loop function call my blink function each time. Every time it loops, it increments and goes to the next value.
I know it's able to pull values from the array fine, as I've tried manually modifying loopCount just before the blink() and it blinks at the specified timeout. I presume the loopCount increment is fine (I also did loopCount++; - no luck).
If someone could point me in the right direction, this would be great. Thanks!