Hey guys, I have a quick question about my Arduino code. I'm trying to get a coin counter working. Basically, I have 4 inputs, and one output. When the Arduino receives a signal from an input, it sends the appropriate amount of pulses to the output. This (http://i.imgur.com/DloK07M.png) is where the output gets sent if you're curious. I know this works, and I don't need any help with this.
Here is my code:
int servo = 13;
int pennyIn = 1;
int nickelIn = 2;
int dimeIn = 3;
int quarterIn = 4;
int coinOut = 7;
void setup() {
Serial.begin(9600);
pinMode(pennyIn, INPUT);
pinMode(nickelIn, INPUT);
pinMode(dimeIn, INPUT);
pinMode(quarterIn, INPUT);
pinMode(servo, OUTPUT);
pinMode(coinOut, OUTPUT);
}
void spin(){
digitalWrite(servo, HIGH);
delayMicroseconds(1300);
digitalWrite(servo, LOW);
delay(20);
}
void coinPulseOut(int value){
Serial.println();
for(int count=0; count<value; count++){
digitalWrite(coinOut, HIGH);
delay(5);
digitalWrite(coinOut, LOW);
delay(5);
Serial.print("pulse");
}
}
void loop() {
spin();
if(digitalRead(pennyIn) == 1){
coinPulseOut(1);
}else if(digitalRead(nickelIn) == 1){
coinPulseOut(5);
}else if(digitalRead(dimeIn) == 1){
coinPulseOut(10);
}else if(digitalRead(quarterIn) == 1){
coinPulseOut(25);
}
}
My problem is whenever I even start the code, the output is spammed with pulses. I can't figure out the problem for the life of me. If anyone can see my mistake, help would be appreciated!
Thanks!