Small Change
Dependencies: APDS_9960 TextLCD mbed
Fork of Si4703 by
main.cpp@1:563a11fe39e0, 2015-10-20 (annotated)
- Committer:
- Gjika
- Date:
- Tue Oct 20 14:58:05 2015 +0000
- Revision:
- 1:563a11fe39e0
- Child:
- 2:8f479ed18d48
Sample Code for Si4703 Digital FM Radio Receiver
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Gjika | 1:563a11fe39e0 | 1 | #include "mbed.h" |
Gjika | 1:563a11fe39e0 | 2 | #include "SparkFun-Si4703.h" |
Gjika | 1:563a11fe39e0 | 3 | #include "TextLCD.h" |
Gjika | 1:563a11fe39e0 | 4 | |
Gjika | 1:563a11fe39e0 | 5 | Serial pc(USBTX, USBRX); |
Gjika | 1:563a11fe39e0 | 6 | Si4703_Breakout radio(p28, p27, p26, &pc); // (sda, scl, rst, Serial) |
Gjika | 1:563a11fe39e0 | 7 | DigitalIn chanUp(p17); |
Gjika | 1:563a11fe39e0 | 8 | DigitalIn chanDown(p18); |
Gjika | 1:563a11fe39e0 | 9 | DigitalIn volUp(p19); |
Gjika | 1:563a11fe39e0 | 10 | DigitalIn volDown(p20); |
Gjika | 1:563a11fe39e0 | 11 | TextLCD lcd(p16, p15, p14, p13, p12, p11); // rs, e, d4-d7 |
Gjika | 1:563a11fe39e0 | 12 | |
Gjika | 1:563a11fe39e0 | 13 | |
Gjika | 1:563a11fe39e0 | 14 | |
Gjika | 1:563a11fe39e0 | 15 | int main(int argc, char** argv) { |
Gjika | 1:563a11fe39e0 | 16 | |
Gjika | 1:563a11fe39e0 | 17 | int chan = 901; |
Gjika | 1:563a11fe39e0 | 18 | int vol = 9; |
Gjika | 1:563a11fe39e0 | 19 | radio.powerOn(); |
Gjika | 1:563a11fe39e0 | 20 | radio.setVolume(vol); // range: 0-15 |
Gjika | 1:563a11fe39e0 | 21 | radio.setChannel(chan); // 90.1 WABE |
Gjika | 1:563a11fe39e0 | 22 | |
Gjika | 1:563a11fe39e0 | 23 | lcd.cls(); |
Gjika | 1:563a11fe39e0 | 24 | lcd.printf("channel = '%d'", radio.getChannel()); |
Gjika | 1:563a11fe39e0 | 25 | lcd.printf(" volume = '%d'\n", radio.getVolume()); |
Gjika | 1:563a11fe39e0 | 26 | pc.printf("channel = '%d'", radio.getChannel()); |
Gjika | 1:563a11fe39e0 | 27 | pc.printf(" volume = '%d'\n", radio.getVolume()); |
Gjika | 1:563a11fe39e0 | 28 | |
Gjika | 1:563a11fe39e0 | 29 | |
Gjika | 1:563a11fe39e0 | 30 | while(1){ |
Gjika | 1:563a11fe39e0 | 31 | if(chanUp) { |
Gjika | 1:563a11fe39e0 | 32 | chan++; |
Gjika | 1:563a11fe39e0 | 33 | radio.setChannel(chan); |
Gjika | 1:563a11fe39e0 | 34 | lcd.cls(); |
Gjika | 1:563a11fe39e0 | 35 | lcd.printf("channel = '%d'", radio.getChannel()); |
Gjika | 1:563a11fe39e0 | 36 | lcd.printf(" volume = '%d'\n", radio.getVolume()); |
Gjika | 1:563a11fe39e0 | 37 | pc.printf("channel = '%d'", radio.getChannel()); |
Gjika | 1:563a11fe39e0 | 38 | pc.printf(" volume = '%d'\n", radio.getVolume()); |
Gjika | 1:563a11fe39e0 | 39 | wait(.25); |
Gjika | 1:563a11fe39e0 | 40 | } |
Gjika | 1:563a11fe39e0 | 41 | if(chanDown) { |
Gjika | 1:563a11fe39e0 | 42 | chan--; |
Gjika | 1:563a11fe39e0 | 43 | radio.setChannel(chan); |
Gjika | 1:563a11fe39e0 | 44 | lcd.cls(); |
Gjika | 1:563a11fe39e0 | 45 | lcd.printf("channel = '%d'", radio.getChannel()); |
Gjika | 1:563a11fe39e0 | 46 | lcd.printf(" volume = '%d'\n", radio.getVolume()); |
Gjika | 1:563a11fe39e0 | 47 | pc.printf("channel = '%d'", radio.getChannel()); |
Gjika | 1:563a11fe39e0 | 48 | pc.printf(" volume = '%d'\n", radio.getVolume()); |
Gjika | 1:563a11fe39e0 | 49 | wait(.25); |
Gjika | 1:563a11fe39e0 | 50 | } |
Gjika | 1:563a11fe39e0 | 51 | if(volUp && vol <= 14) { |
Gjika | 1:563a11fe39e0 | 52 | vol++; |
Gjika | 1:563a11fe39e0 | 53 | radio.setVolume(vol); |
Gjika | 1:563a11fe39e0 | 54 | lcd.cls(); |
Gjika | 1:563a11fe39e0 | 55 | lcd.printf("channel = '%d'", radio.getChannel()); |
Gjika | 1:563a11fe39e0 | 56 | lcd.printf(" volume = '%d'\n", radio.getVolume()); |
Gjika | 1:563a11fe39e0 | 57 | pc.printf("channel = '%d'", radio.getChannel()); |
Gjika | 1:563a11fe39e0 | 58 | pc.printf(" volume = '%d'\n", radio.getVolume()); |
Gjika | 1:563a11fe39e0 | 59 | wait(.25); |
Gjika | 1:563a11fe39e0 | 60 | } |
Gjika | 1:563a11fe39e0 | 61 | if(volUp && vol == 15) { |
Gjika | 1:563a11fe39e0 | 62 | lcd.cls(); |
Gjika | 1:563a11fe39e0 | 63 | lcd.printf("channel = '%d'", radio.getChannel()); |
Gjika | 1:563a11fe39e0 | 64 | lcd.printf(" Max Volume\n", radio.getVolume()); |
Gjika | 1:563a11fe39e0 | 65 | pc.printf("Max Volume\n"); |
Gjika | 1:563a11fe39e0 | 66 | wait(.25); |
Gjika | 1:563a11fe39e0 | 67 | } |
Gjika | 1:563a11fe39e0 | 68 | if(volDown && vol >= 1) { |
Gjika | 1:563a11fe39e0 | 69 | vol--; |
Gjika | 1:563a11fe39e0 | 70 | radio.setVolume(vol); |
Gjika | 1:563a11fe39e0 | 71 | lcd.cls(); |
Gjika | 1:563a11fe39e0 | 72 | lcd.printf("channel = '%d'", radio.getChannel()); |
Gjika | 1:563a11fe39e0 | 73 | lcd.printf(" volume = '%d'\n", radio.getVolume()); |
Gjika | 1:563a11fe39e0 | 74 | pc.printf("channel = '%d'", radio.getChannel()); |
Gjika | 1:563a11fe39e0 | 75 | pc.printf(" volume = '%d'\n", radio.getVolume()); |
Gjika | 1:563a11fe39e0 | 76 | wait(.25); |
Gjika | 1:563a11fe39e0 | 77 | } |
Gjika | 1:563a11fe39e0 | 78 | if(volDown && vol == 0) { |
Gjika | 1:563a11fe39e0 | 79 | lcd.cls(); |
Gjika | 1:563a11fe39e0 | 80 | lcd.printf("channel = '%d'", radio.getChannel()); |
Gjika | 1:563a11fe39e0 | 81 | lcd.printf(" Min Volume\n", radio.getVolume()); |
Gjika | 1:563a11fe39e0 | 82 | pc.printf("Min Volume\n"); |
Gjika | 1:563a11fe39e0 | 83 | wait(.25); |
Gjika | 1:563a11fe39e0 | 84 | } |
Gjika | 1:563a11fe39e0 | 85 | |
Gjika | 1:563a11fe39e0 | 86 | } |
Gjika | 1:563a11fe39e0 | 87 | } |