Self made shake switch
dear arduino-fans!
i new arduino , i've set project.
i've made own shake-switch, if shake thing, makes contact, in every direction. (he working)
it made piece of polystyrene, nails, small spring weight @ end , screw.



now want program arduino.
i want make led blink when has made contact 5 times in 2 seconds.
so thinking:
but not work! ;(
and have no clue how turn off again when shaking(making contact) 5 times in 2 seconds again.
i think somewhere there has be:
i've done lot of research, not make work!
thanks,
samory
i new arduino , i've set project.
i've made own shake-switch, if shake thing, makes contact, in every direction. (he working)
it made piece of polystyrene, nails, small spring weight @ end , screw.
now want program arduino.
i want make led blink when has made contact 5 times in 2 seconds.
so thinking:
code: [select]
int ledpin7 = 7;
int inpin4 = 4;
int val = 0;
int buttonpushcounter = 0; // counter number of button presses
int buttonstate = 0; // current state of button
int lastbuttonstate = 0; // previous state of button
long firstpress = 0;
long countingtime = 3000;
int presses = 0;
void setup()
{
pinmode(ledpin7,output);
pinmode(inpin2, input);
}
void loop()
{
if(digitalread(inpin4) == high)
{
firstpress = millis();
presses = 1;
while(millis() - firstpress < countingtime)
{
if(digitalread(inpin4) == high)
{
presses++;
}
}
if(digitalread(inpin4) == high)
{
firstpress = millis();
presses = 5;
digitalwrite(ledpin7,high);
}
}
}
but not work! ;(
and have no clue how turn off again when shaking(making contact) 5 times in 2 seconds again.
i think somewhere there has be:
code: [select]
if(button_count == 21) button_count =0;
i've done lot of research, not make work!
thanks,
samory
first things first - doesn't compile. looks typo on pinmode line sets input. badly needs attention of ide's autoformatter.
after you'll need @ debouncing input - tight while loop have register many many presses. purpose of code after while loop eludes me.
after you'll need @ debouncing input - tight while loop have register many many presses. purpose of code after while loop eludes me.
Arduino Forum > Using Arduino > Programming Questions > Self made shake switch
arduino
Comments
Post a Comment