Pushbutton for favourite stations
Turning the station dial is lots of fun, but I wanted to have fast access to some favourite stations ... so I added some push-buttons.

8 Pushbottons by RigasW, on Flickr
I used a shiftIn registered as described in the tutorial here in arduino.cc to address the buttons.
If you want to save a station number to a button, you have to do the following:
- Select the sation by turning the tuning dial.
- Go into freeze mode
- Press the button, that you want to use for that station
- The station number is written in eeprom
- Exit freeze mode.
If you now press the station button, SlugRadio switches to the saved station. In addition, a led lights up, indicating, that you are listening to a programmed station.
Here is part of the code:
buttonState = digitalRead(buttonPin);
switch(StationKeyState) {
case NonStationKeyMode:
// you have to be in freeze mode; then pressing the station button will save the station value im eeprom.
if (((switchVar1 & B10000000) == B10000000) & programState == FreezeMode) {
digitalWrite(ledPin, HIGH);
delay(300);
digitalWrite(ledPin, LOW);
EEPROM.write(1, tunerValue);
}
if (((switchVar1 & B00000100) == B00000100) & programState == FreezeMode){
digitalWrite(ledPin, HIGH);
delay(300);
digitalWrite(ledPin, LOW);
EEPROM.write(2, tunerValue);
}
if (((switchVar1 & B00000010) == B00000010) & programState == FreezeMode){
digitalWrite(ledPin, HIGH);
delay(300);
digitalWrite(ledPin, LOW);
EEPROM.write(3, tunerValue);
}
if (((switchVar1 & B00001000) == B00001000) & programState == FreezeMode){
digitalWrite(ledPin, HIGH);
delay(300);
digitalWrite(ledPin, LOW);
EEPROM.write(4, tunerValue);
}
if (((switchVar1 & B00000001) == B00000001) & programState == FreezeMode){
digitalWrite(ledPin, HIGH);
delay(300);
digitalWrite(ledPin, LOW);
EEPROM.write(5, tunerValue);
}
if (((switchVar1 & B00010000) == B00010000) & programState == FreezeMode){
digitalWrite(ledPin, HIGH);
delay(300);
digitalWrite(ledPin, LOW);
EEPROM.write(6, tunerValue);
}
// pressing the station botton in regular operation will get the station value from eeprom.
if ((switchVar1 & B10000000) == B10000000){
tunerValue = EEPROM.read(1);
StationKeyState = StationKeyMode;
digitalWrite(ledPin, HIGH);
}
if ((switchVar1 & B00000100) == B00000100){
tunerValue = EEPROM.read(2);
StationKeyState = StationKeyMode;
digitalWrite(ledPin, HIGH);
}
if ((switchVar1 & B00000010) == B00000010){
tunerValue = EEPROM.read(3);
StationKeyState = StationKeyMode;
digitalWrite(ledPin, HIGH);
}
if ((switchVar1 & B00001000) == B00001000){
tunerValue = EEPROM.read(4);
StationKeyState = StationKeyMode;
digitalWrite(ledPin, HIGH);
}
if ((switchVar1 & B00000001) == B00000001){
tunerValue = EEPROM.read(5);
StationKeyState = StationKeyMode;
digitalWrite(ledPin, HIGH);
}
if ((switchVar1 & B00010000) == B00010000){
tunerValue = EEPROM.read(6);
StationKeyState = StationKeyMode;
digitalWrite(ledPin, HIGH);
}
break;
case StationKeyMode
if ((switchVar1 & B10000000) == B10000000){
StationKeyState = NonStationKeyMode;
digitalWrite(ledPin, LOW);
}
if ((switchVar1 & B00000100) == B00000100){
StationKeyState = NonStationKeyMode;
digitalWrite(ledPin, LOW);
}
if ((switchVar1 & B00000010) == B00000010){
StationKeyState = NonStationKeyMode;
digitalWrite(ledPin, LOW);
}
if ((switchVar1 & B00001000) == B00001000){
StationKeyState = NonStationKeyMode;
digitalWrite(ledPin, LOW);
}
if ((switchVar1 & B00000001) == B00000001){
StationKeyState = NonStationKeyMode;
digitalWrite(ledPin, LOW);
}
if ((switchVar1 & B00010000) == B00010000){
StationKeyState = NonStationKeyMode;
digitalWrite(ledPin, LOW);
}
break;
default:
programState = NonStationKeyMode;
break;
}
Enjoy!
Schwabinger