Hardware Reference
In-Depth Information
You can then adapt the similarly banal Arduino control program to check for three buttons instead of one,
remembering to debounce each of them. There's also a slight change here; because you're using the record button
to govern the length of the record, consequently it sends a start message when the button is pressed and a stop
message on release.
int pinStates[3];
int lastStates[3];
long timesLastPressed[3];
int inputSwitchPins[3] = {2,3,4};
void setup() {
Serial.begin(9600);
for(int i=0;i<3;++i) {
pinMode(inputSwitchPins[i], INPUT);
lastState = digitalRead(inputSwitchPins[i]);
timesLastPressed[i] = millis();
}
}
void loop() {
for(int i=0;i<3;++i) {
int pinState = digitalRead(inputSwitchPins[i]);
if (pinState != lastStates[i] &&
millis() - timesLastPressed[i] > debouncePeriod) {
switch(i) {
case 0: // record
Serial.print(pinState==0?"B":"E");
break;
case 1: // play
if (pinState == 0) {
Serial.print("P");
}
break;
case 2: // delete
if (pinState == 0) {
Serial.print("D");
}
break;
}
timesLastPressed[i] = millis();
lastStates[i] = pinState;
}
}
}
Search WWH ::




Custom Search