Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: APDS_9960 TextLCD mbed
Fork of Si4703 by
main.cpp
00001 /* 00002 Gesture Controlled Radio 00003 Nick Ciulla and Michelle Nguyen 00004 00005 Thanks to Simon Monk for library use. 00006 00007 00008 00009 */ 00010 00011 00012 #include "mbed.h" 00013 #include "SparkFun-Si4703.h" 00014 #include "TextLCD.h" 00015 #include "glibr.h" 00016 00017 Serial pc(USBTX, USBRX); 00018 Si4703_Breakout radio(PTD9, PTD8, PTB11, &pc); // (sda, scl, rst, Serial) PTD9, PTD8, PTB11, &pc); 00019 DigitalIn chanUp(PTC16); 00020 DigitalIn chanDown(PTC17); 00021 DigitalIn volUP(PTA12); 00022 DigitalIn volDown(PTA13); 00023 TextLCD lcd(PTE6, PTD15, PTD4, PTD5, PTD6, PTD7); // rs, e, d4-d7 00024 glibr GSensor(PTD9,PTD8); //sda, scl 00025 00026 00027 int main(int argc, char** argv) { 00028 00029 int playlist[3] = {963, 1045, 1033}; //hardcoded stations that work 00030 int numtot =3; //total number of stations 00031 int isr_flag = 0; 00032 int chan = 0; 00033 int vol = 5; 00034 radio.powerOn(); 00035 radio.setVolume(vol); // range: 0-15 set to 1-5 for testing ... loud 00036 radio.setChannel(playlist[chan]); 00037 00038 00039 lcd.cls(); 00040 lcd.printf("channel = '%d'", radio.getChannel()); 00041 lcd.printf(" volume = '%d'\n", radio.getVolume()); 00042 pc.printf("channel = '%d'", radio.getChannel()); 00043 pc.printf(" volume = '%d'\n", radio.getVolume()); 00044 00045 if ( GSensor.ginit() ) { 00046 pc.printf("APDS-9960 initialization complete\r\n"); 00047 } else { 00048 pc.printf("Something went wrong during APDS-9960 init\r\n"); 00049 return -1; 00050 } 00051 00052 // Start running the APDS-9960 gesture sensor engine 00053 if ( GSensor.enableGestureSensor(true) ) { 00054 pc.printf("Gesture sensor is now running\r\n"); 00055 } else { 00056 pc.printf("Something went wrong during gesture sensor init!\r\n"); 00057 return -1; 00058 } 00059 while(1){ 00060 00061 if ( GSensor.isGestureAvailable() ) { // gesture detect 00062 switch ( GSensor.readGesture() ) { // gesture differentiate 00063 case DIR_UP: 00064 00065 00066 chan++; 00067 if (chan == (numtot)) //works like a normal radio ... will loop 00068 { 00069 chan = 0; 00070 pc.printf("Back to the start!\r\n"); 00071 } 00072 00073 radio.setChannel(playlist[chan%numtot]); 00074 lcd.cls(); 00075 lcd.printf("channel = '%d'", radio.getChannel()); 00076 lcd.printf(" volume = '%d'\n", radio.getVolume()); 00077 pc.printf("channel = '%d'", radio.getChannel()); 00078 pc.printf(" volume = '%d'\n", radio.getVolume()); 00079 00080 pc.printf("UP\r\n"); 00081 break; 00082 case DIR_DOWN: 00083 if (chan ==0) 00084 { 00085 chan = numtot; 00086 pc.printf("Around to the top!\r\n"); 00087 } 00088 00089 chan--; 00090 00091 radio.setChannel(playlist[chan%numtot]); 00092 lcd.cls(); 00093 lcd.printf("channel = '%d'", radio.getChannel()); 00094 lcd.printf(" volume = '%d'\n", radio.getVolume()); 00095 pc.printf("channel = '%d'", radio.getChannel()); 00096 pc.printf(" volume = '%d'\n", radio.getVolume()); 00097 00098 pc.printf("DOWN\r\n"); 00099 break; 00100 case DIR_LEFT: 00101 vol++; 00102 radio.setVolume(vol); 00103 lcd.cls(); 00104 lcd.printf("channel = '%d'", radio.getChannel()); 00105 lcd.printf(" volume = '%d'\n", radio.getVolume()); 00106 pc.printf("channel = '%d'", radio.getChannel()); 00107 pc.printf(" volume = '%d'\n", radio.getVolume()); 00108 00109 pc.printf("LEFT\r\n"); 00110 break; 00111 case DIR_RIGHT: 00112 vol--; 00113 radio.setVolume(vol); 00114 lcd.cls(); 00115 lcd.printf("channel = '%d'", radio.getChannel()); 00116 lcd.printf(" volume = '%d'\n", radio.getVolume()); 00117 pc.printf("channel = '%d'", radio.getChannel()); 00118 pc.printf(" volume = '%d'\n", radio.getVolume()); 00119 00120 pc.printf("RIGHT\r\n"); 00121 break; 00122 case DIR_NEAR: 00123 pc.printf("NEAR\r\n"); 00124 break; 00125 case DIR_FAR: 00126 pc.printf("FAR\r\n"); 00127 break; 00128 default: 00129 pc.printf("NONE\r\n"); 00130 break; 00131 } 00132 00133 } 00134 00135 } 00136 }
Generated on Thu Jul 28 2022 05:03:58 by
1.7.2
