microrobotics

Untitled

Aug 6th, 2017
1,181
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Si4703_Breakout.h>
  2. #include <Wire.h>
  3.  
  4. int resetPin = 2;
  5. int SDIO = A4;
  6. int SCLK = A5;
  7.  
  8. Si4703_Breakout radio(resetPin, SDIO, SCLK);
  9. int channel;
  10. int volume;
  11. char rdsBuffer[10];
  12.  
  13. void setup()
  14. {
  15.   Serial.begin(9600);
  16.   Serial.println("\n\nSi4703_Breakout Test Sketch");
  17.   Serial.println("===========================");  
  18.   Serial.println("a b     Favourite stations");
  19.   Serial.println("+ -     Volume (max 15)");
  20.   Serial.println("u d     Seek up / down");
  21.   Serial.println("r       Listen for RDS Data (15 sec timeout)");
  22.   Serial.println("Send me a command letter.");
  23.  
  24.  
  25.   radio.powerOn();
  26.   radio.setVolume(0);
  27. }
  28.  
  29. void loop()
  30. {
  31.   if (Serial.available())
  32.   {
  33.     char ch = Serial.read();
  34.     if (ch == 'u')
  35.     {
  36.       channel = radio.seekUp();
  37.       displayInfo();
  38.     }
  39.     else if (ch == 'd')
  40.     {
  41.       channel = radio.seekDown();
  42.       displayInfo();
  43.     }
  44.     else if (ch == '+')
  45.     {
  46.       volume ++;
  47.       if (volume == 16) volume = 15;
  48.       radio.setVolume(volume);
  49.       displayInfo();
  50.     }
  51.     else if (ch == '-')
  52.     {
  53.       volume --;
  54.       if (volume < 0) volume = 0;
  55.       radio.setVolume(volume);
  56.       displayInfo();
  57.     }
  58.     else if (ch == 'a')
  59.     {
  60.       channel = 930; // Rock FM
  61.       radio.setChannel(channel);
  62.       displayInfo();
  63.     }
  64.     else if (ch == 'b')
  65.     {
  66.       channel = 974; // BBC R4
  67.       radio.setChannel(channel);
  68.       displayInfo();
  69.     }
  70.     else if (ch == 'r')
  71.     {
  72.       Serial.println("RDS listening");
  73.       radio.readRDS(rdsBuffer, 15000);
  74.       Serial.print("RDS heard:");
  75.       Serial.println(rdsBuffer);      
  76.     }
  77.   }
  78. }
  79.  
  80. void displayInfo()
  81. {
  82.    Serial.print("Channel:"); Serial.print(channel);
  83.    Serial.print(" Volume:"); Serial.println(volume);
  84. }
RAW Paste Data