please halp me with my codes!...
i have working code arduino , want load of 1 button (start-stop)
// setup function runs once when press reset or power board
void setup() {
// initialize digital pin 9 output.
pinmode(9, output);
pinmode(8, output);
pinmode(7, output);
pinmode(6, output);
pinmode(5, output);
digitalwrite(9, high); // turn led on (high voltage level)
delay(1000); // wait second
digitalwrite(6, high); // turn led on (high voltage level)
delay(3000); // wait second
digitalwrite(8, high); // turn led on (high voltage level)
delay(1000); // wait second
digitalwrite(7, high); // turn led on (high voltage level)
delay(1000); // wait second
digitalwrite(6, low); // turn led off making voltage low
delay(1000); // wait second
digitalwrite(9, low); // turn led off making voltage low
delay(1000); // wait second
digitalwrite(5, high);(delay(1000)) ; digitalwrite(6, high); // turn led on (high voltage level)
delay(20000); // wait second delay(20000);
digitalwrite(6, high); // turn led on (high voltage level)
delay(1000); // wait second
digitalwrite(6, low); // turn led off making voltage low
delay(1000); // wait second
digitalwrite(5, low); // turn led off making voltage low
delay(1000); // wait second
digitalwrite(6, high); // turn led on (high voltage level)
delay(20000); // wait second
digitalwrite(7, low); // turn led off making voltage low
delay(1000); // wait second
digitalwrite(8, low); // turn led off making voltage low
delay(1000); // wait second
digitalwrite(6, low); // turn led off making voltage low
delay(1000); // wait second
}
// loop function runs on , on again forever
void loop() {
}
this code works , once , , want code work , click on button...
i need how have insert button, leds illuminated on order?!..
// setup function runs once when press reset or power board
void setup() {
// initialize digital pin 9 output.
pinmode(9, output);
pinmode(8, output);
pinmode(7, output);
pinmode(6, output);
pinmode(5, output);
digitalwrite(9, high); // turn led on (high voltage level)
delay(1000); // wait second
digitalwrite(6, high); // turn led on (high voltage level)
delay(3000); // wait second
digitalwrite(8, high); // turn led on (high voltage level)
delay(1000); // wait second
digitalwrite(7, high); // turn led on (high voltage level)
delay(1000); // wait second
digitalwrite(6, low); // turn led off making voltage low
delay(1000); // wait second
digitalwrite(9, low); // turn led off making voltage low
delay(1000); // wait second
digitalwrite(5, high);(delay(1000)) ; digitalwrite(6, high); // turn led on (high voltage level)
delay(20000); // wait second delay(20000);
digitalwrite(6, high); // turn led on (high voltage level)
delay(1000); // wait second
digitalwrite(6, low); // turn led off making voltage low
delay(1000); // wait second
digitalwrite(5, low); // turn led off making voltage low
delay(1000); // wait second
digitalwrite(6, high); // turn led on (high voltage level)
delay(20000); // wait second
digitalwrite(7, low); // turn led off making voltage low
delay(1000); // wait second
digitalwrite(8, low); // turn led off making voltage low
delay(1000); // wait second
digitalwrite(6, low); // turn led off making voltage low
delay(1000); // wait second
}
// loop function runs on , on again forever
void loop() {
}
this code works , once , , want code work , click on button...
i need how have insert button, leds illuminated on order?!..
quote
this code works , once , , want code work , click on button...you must know code in setup() runs once.
move things loop()
get rid of delay()s
look @ example, might give insight:
code: [select]
// program sequentially turn on , turn off 3 leds
const byte led1 = 2;
const byte led2 = 3;
const byte led3 = 4;
const byte heartbeat = 13;
boolean blockingflag = true;
unsigned long millis13;
unsigned long lastmillis;
unsigned long wait = 3000;
enum states {
statestart, state2, state3, state4, state5, state6, state7
};
states mstate = statestart;
void setup()
{
pinmode(heartbeat, output);
pinmode(led1, output);
pinmode(led2, output);
pinmode(led3, output);
delay(3000);
} //end of setup()
void loop()
{
//**********************************
//some code check blocking sketches
if (millis() - millis13 >= 200)
{
digitalwrite(heartbeat, !digitalread(heartbeat)); //toggle d13
millis13 = millis(); //re-initalize
}
//********************************** delay() being used here
if (blockingflag == true)
{
blockingflag = false;
digitalwrite(13, low);
blockingmethod();
}
//********************************** bwd being used here
if (millis() - lastmillis >= wait)
{
nonblockingmethod();
}
//other non blocking code goes here
} //end of loop()
// ******************* functions *******************
void blockingmethod()
{
//leds on
digitalwrite(led3, high); // turn on led3
delay(450); // wait 450ms
digitalwrite(led2, high); // turn on led2
delay(450); // wait 450ms
digitalwrite(led1, high); // turn on led1
delay(3000); // wait 3000ms
//leds off
digitalwrite(led3, low); // turn off led3
delay(450); // wait 450ms
digitalwrite(led2, low); // turn off led2
delay(450); // wait 450ms
digitalwrite(led1, low); // turn off led1
delay(3000); // wait 3000ms
} //end of blockingmethod()
void nonblockingmethod()
{
switch (mstate)
{
//*************************** //leds on
case statestart:
{
digitalwrite(led3, high); // turn on led3
wait = 450; // wait 450ms
lastmillis = millis();
mstate = state2;
}
break;
//***************************
case state2:
{
digitalwrite(led2, high); // turn on led2
wait = 450; // wait 450ms
lastmillis = millis();
mstate = state3;
}
break;
//***************************
case state3:
{
digitalwrite(led1, high); // turn on led1
wait = 3000; // wait 3000ms
lastmillis = millis();
mstate = state4;
}
break;
//*************************** //leds off
case state4:
{
digitalwrite(led3, low); // turn off led3
wait = 450; // wait 450ms
lastmillis = millis();
mstate = state5;
}
break;
//***************************
case state5:
{
digitalwrite(led2, low); // turn off led2
wait = 450; // wait 450ms
lastmillis = millis();
mstate = state6;
}
break;
//***************************
case state6:
{
digitalwrite(led1, low); // turn off led1
wait = 3000; // wait 3000ms
lastmillis = millis();
mstate = state7;
}
break;
//***************************
case state7:
{
blockingflag = true;
wait = 3000; // wait 3000ms
mstate = statestart;
}
break;
//***************************
default:
{
}
break;
} //end of switch case
} //end of nonblockingmethod()
// ************** end of sketch ****************
.
Arduino Forum > Using Arduino > LEDs and Multiplexing > please halp me with my codes!...
arduino
Comments
Post a Comment