Im trying to use the Blink without Delay code but it gose on for 1000; and off for 1000; how can i make it go on for 300; and off for 1000; ?
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
*/
// constants won't change. Used here to
// set pin numbers:
const int ledPin = 13; // the number of the LED pin
// Variables will change:
int ledState = LOW; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updated
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000; // interval at which to blink (milliseconds)
void setup() {
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
}
void loop()
{
// here is where you'd put code that needs to be running all the time.
// check to see if it's time to blink the LED; that is, if the
// difference between the current time and last time you blinked
// the LED is bigger than the interval at which you want to
// blink the LED.
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}
}
You are doing the same thing 3 times. Each time with variable1, variable2 variable3 ... Using arrays avoids repeating the same code.
Variable[1] Variable[2] Variable[3] replaces the indivdual ones. That does not save anything.
But then we use Variable[idx] and let idx take on the values 1, 2, and 3.
This means your code becomes (only showing parts)
int ledPin[] = { 30, 31, 32 } ;
int ledState[] = { LOW, LOW, LOW } ;
unsigned long ofTime = { 2000, 4000 , 4000 } ;
// and so on for all
void setup() {
for ( int idx = 0 ; idx < 3 ; idx++ ) // for all defined pins...
pinMode(ledPin[idx],OUTPUT) ; // ..set them to output
}
void loop() {
currentMillis = millis() ;
for ( idx = 0 ; idx < 3 ; idx++ ) { // for all defined LEDs, do :
if (currentMillis - previousMillis[idx] > interval[idx])
{
previousMillis[idx] = currentMillis;
if (ledState[idx] == LOW)
{
ledState[idx] = HIGH;
interval[idx] = onTime[idx];
:
} // close brace that matches the for
} // end loop
So you only need to write your code once. There are a few more tricks with arrays but this will get you the essentials.
"not working" could be anything from smoke out of the LED to one LED blinking at the wrong rate. Presumably you are somewhere between.
The code I wrote was showing the principle by "transforming" some of your code, but it got to just a tedious editing exercise after the first few lines, so look at your code, the bit I have made and make similar edits to your code. You need to declare more arrays, too (same lazy reasoning from me). You can not use #define as arrays, so they become ordinary array/variables