Hi everyone,
Just a quick thing,
Im trying to interface my Arduino with my mac so that when I press one of 5 buttons on the arduino board it transferes a character to the mac via serial.
Ive written the code, however when I plug the board into the mac it will randomly think that one of the buttons has been pressed.
Code:
int next = 2; // Next button
int prev = 3; // Prev button
int play = 4; // play/pause button
int louder = 5; // Vol UP button
int quiter = 6; // VOL down button
int val_next = 0; // variable for reading the pin status
int val_prev = 0; // variable for reading the pin status
int val_play = 0; // variable for reading the pin status
int val_louder = 0; // variable for reading the pin status
int val_quiter = 0; // variable for reading the pin status
void setup() {
Serial.begin(9600);
pinMode(next, INPUT); // declare NEXT as input
pinMode(prev, INPUT); // declare Prevous as input
pinMode(play, INPUT); // declare PLAY / PAUSE as input
pinMode(louder, INPUT); // declare Louder Volume as input
pinMode(quiter, INPUT); // declare Quiter Volume as input
digitalWrite(next, LOW);
digitalWrite(prev, LOW);
digitalWrite(play, LOW);
digitalWrite(louder, LOW);
digitalWrite(quiter, LOW);
digitalWrite(val_next, LOW);
digitalWrite(val_prev, LOW);
digitalWrite(val_play, LOW);
digitalWrite(val_louder, LOW);
digitalWrite(val_quiter, LOW);
}
void loop(){
val_next = digitalRead(next); // read input value
val_prev = digitalRead(prev); // read input value
val_play = digitalRead(play); // read input value
val_louder = digitalRead(louder); // read input value
val_quiter = digitalRead(quiter); // read input value
if (val_next == LOW) { // check if the input is HIGH (button released)
Serial.println("A");
digitalWrite(next, LOW);
delay(1000);
}
if (val_prev == LOW) { // check if the input is HIGH (button released)
Serial.println("B");
digitalWrite(prev, LOW);
delay(1000);
}
if (val_play == LOW) { // check if the input is HIGH (button released)
Serial.println("C");
digitalWrite(play, LOW);
delay(1000);
}
if (val_louder == LOW) { // check if the input is HIGH (button released)
Serial.println("D");
digitalWrite(louder, LOW);
delay(1000);
}
if (val_quiter == LOW) { // check if the input is HIGH (button released)
Serial.println("E");
digitalWrite(quiter, LOW);
delay(1000);
}
}
Any ideas?
Thanks
Mathew