this is a small perimeter sensor type project that counts on bar graph how many times the beam has been broken..
when laser is not recognized, int graphLed increases by 1 and lights the next LED in the bar graph.
question is about software reset. I want to push switch and reset counter. I use pin 12 that I jump to reset pin on the board. If I declare pin type before setting it high or low, it will go low FIRST and get forever loop.
I read somewhere that you have to set PIN to HIGH prior to declaring type. I make pin HIGH prior to declaring a type which seems to work.
so when momentary switch (switchpin) is pressed, it sets switchpin 13 = 1 which sets pin 12 to LOW and then system restarts.
problem is when button is pressed it appears to go into a forever loop.
I have to unplug and plug back in to get to work again.
why would it work fine when first plugged in, but not work after a restart?
any, simple way around this?
can I wire the momentary switch (3 conductors, vcc, gnd, signal) somehow directly to the reset switch and not have a pin set another pin?
I just dont know what to do next to fix this.
I really want to use this particular switch.. they are cheap and work well.
thanks in advance!
Pete
int laserPin = 14;
int switchPin = 13;
int resetPin = 12;
int graphLed = 2;
void setup() {
pinMode(2,OUTPUT); //led 1
pinMode(3,OUTPUT); //led 2
pinMode(4, OUTPUT); //led 3
pinMode(5, OUTPUT); //led 4
pinMode(6, OUTPUT); //led 5
pinMode(7, OUTPUT); //led 6
pinMode(8, OUTPUT); //led 7
pinMode(9, OUTPUT); //led 8
pinMode(10, OUTPUT); //led9
pinMode(11, OUTPUT); //led 10
pinMode(13, INPUT); //switchpin
pinMode(14, INPUT);//laserpin
pinMode(15, OUTPUT);//red activity LED
digitalWrite(2,LOW); //led 1
digitalWrite(3,LOW);//led 2
digitalWrite(4,LOW);//led 3
digitalWrite(5,LOW);//led 4
digitalWrite(6,LOW);//led 5
digitalWrite(7,LOW);//led 6
digitalWrite(8,LOW);//led 7
digitalWrite(9,LOW);//led 8
digitalWrite(10,LOW);//led9
digitalWrite(11,LOW);//led 10
digitalWrite(13,LOW);//switchpin
digitalWrite(14,LOW);//laserpin
digitalWrite(15,LOW);//red activity LED
delay(10);
digitalWrite(12,HIGH); //resetpin
delay(10);
pinMode(12,OUTPUT); // resetpin
}
void loop() {
int switchState = digitalRead(switchPin);
int laserState = digitalRead(laserPin);
if (graphLed == 12){
digitalWrite(2,LOW); //led 1
digitalWrite(3,LOW);//led 2
digitalWrite(4,LOW);//led 3
digitalWrite(5,LOW);//led 4
digitalWrite(6,LOW);//led 5
digitalWrite(7,LOW);//led 6
digitalWrite(8,LOW);//led 7
digitalWrite(9,LOW);//led 8
digitalWrite(10,LOW);//led9
digitalWrite(11,LOW);//led 10
graphLed = 2;}
if (switchState == 1) {
digitalWrite(resetPin,LOW);
}
if (laserState == 0) {
digitalWrite (graphLed, HIGH);
graphLed = graphLed + 1;
digitalWrite (15, HIGH);
delay (2000);
digitalWrite (15, LOW);}
}
Here are the components I used:
arduino pro mini
laser receiver module
10 Segment Digital Red LED Bar Graph
http://www.ebay.com/itm/111968067497?_trksid=p2060353.m2749.l2649
Hot Digital Touch Sensor Module Capacitive Switch
http://www.ebay.com/itm/291714864388?_trksid=p2060353.m2749.l2649