Arduino push Button -
i need in arduino uno r3 push button. using registers without using pinmode, digitalwrite, digitalread if-else, , switch-case.
int led1=2, led2=3, led3=4, led4=5; int led5=8, led6=9, led7=10, led8=11; int button=12; int i,j,k; void setup() { ddrb=ddrb|b00001111; ddrd=ddrd|b00111100; serial.begin (9600); } void loop() { int f=0; for(int s=0;s<16;s++){ int k=0; int i=0b00001; int j=0b0011; portb=f; f +=1; if (f==64){f=0;} portd=0; for(k=0;k<7;k++){ delay(250); portd=i; delay(250); portd=j; i=(i<<1); j=(j<<1); } j=(j>>1); for(int d=0; d<9; d++){ delay(250); portd=i; delay(250); portd=j; i=(i>>1); j=(j>>1); } } }
this code. need make while loop push button. when push button program start , when push button again program stop.
well, can in 2 way.
first one
the simple 1 writing , reading byte directly into/fom eeprom. everytime press push button, need read first , validate value. lets supose byte means 0 turned off , 1 turned on. if push button , saved byte 0, need change 1.
you going write using this: https://www.arduino.cc/en/tutorial/eepromwrite
after management, need read byte inside loop statement. if byte 1, thread can executed.
you going read using this: https://www.arduino.cc/en/tutorial/eepromread
second
this cannon kill mosquito, can reused later manage other kinds of informations. going use same logic, saving more detailed or complex values. talking kind of database.
http://playground.arduino.cc/code/databaselibrary
i'm sorry can't write sample code right now. job first. if can't untill end of day, maybe can come later , comlete post out.
Comments
Post a Comment