for each button pressed nucleo sends a command, used to interface citroen steering wheel command to keenwood car radio
Dependencies: MBC002-DigitalIn
Fork of steering_wheel_controls_TO_KEENWOOD_RADIO_INFRARED_INTERFACE by
main.cpp@10:4ff4a376a6fd, 2018-07-04 (annotated)
- Committer:
- lucaVisconti
- Date:
- Wed Jul 04 13:49:20 2018 +0000
- Revision:
- 10:4ff4a376a6fd
- Parent:
- 9:33d8b36e81d4
STM32 NUCLEO-F401RE steering wheel command infrared interface to KEENWOOD CAR RADIO
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
leandropg | 0:4265ec26da85 | 1 | #include "mbed.h" |
leandropg | 0:4265ec26da85 | 2 | |
lucaVisconti | 10:4ff4a376a6fd | 3 | // DEFINE AN ARRAY FOR EACH COMMAND YOU NEED, IT CONTAINS A SEQUENCE OF VALUE FOR EACH COMMAND WE NEED, |
lucaVisconti | 10:4ff4a376a6fd | 4 | // SEE DOCUMENTATION: COMMAND PROTOCOL DETAILS |
lucaVisconti | 8:f8a9b7dbf399 | 5 | |
lucaVisconti | 10:4ff4a376a6fd | 6 | int ARRAY_SOURCE[] = {342,171,21,64,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,21,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,64,21,64,21,21,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,64,21,64,21,21,21,64,21,64,21,64,21}; |
lucaVisconti | 10:4ff4a376a6fd | 7 | int ARRAY_TEL[] = {342,171,21,64,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,21,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,21,21,64,21,21,21,21,21,64,21,21,21,21,21,64,21,64,21,21,21,64,21,64,21,21,21,64,21,64,21,21,21}; |
lucaVisconti | 10:4ff4a376a6fd | 8 | int ARRAY_VOLUP[] = {342,171,21,64,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,21,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,21,21,21,21,64,21,21,21,64,21,21,21,21,21,21,21,64,21,64,21,21,21,64,21,21,21,64,21,64,21,64,21,1}; |
lucaVisconti | 10:4ff4a376a6fd | 9 | int ARRAY_VOLDWN[] = {342,171,21,64,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,21,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,64,21,21,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,64,21,21,21,64,21,21,21,64,21,64,21,64,21}; |
lucaVisconti | 10:4ff4a376a6fd | 10 | int ARRAY_FF[] = {342,171,21,64,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,21,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,64,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,21,21,64,21,64,21,64,21,64,21}; |
lucaVisconti | 10:4ff4a376a6fd | 11 | int ARRAY_RR[] = {342,171,21,64,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,21,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,21,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,64,21,21,21,64,21,21,21,64,21,64,21,64,21,64,21}; |
lucaVisconti | 10:4ff4a376a6fd | 12 | int ARRAY_ROTUP[] = {342,171,21,64,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,21,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,64,21,21,21,64,21,64,21,21,21,21,21,21,21,21,21,21,21,64,21,21,21,21,21,64,21,64,21,64,21,64,21}; |
lucaVisconti | 10:4ff4a376a6fd | 13 | int ARRAY_ROTDWN[] = {342,171,21,64,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,21,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,21,21,21,21,64,21,64,21,21,21,21,21,21,21,21,21,64,21,64,21,21,21,21,21,64,21,64,21,64,21,64,21}; |
lucaVisconti | 10:4ff4a376a6fd | 14 | |
lucaVisconti | 10:4ff4a376a6fd | 15 | //DEFINE MY OUTPUTS: "led" is IRLED (anode connected on PC_0, catode on GND), "myled" is STM32 NUCLEO board-led |
lucaVisconti | 1:1bd5272d7a1f | 16 | DigitalOut myled(LED1); |
leandropg | 0:4265ec26da85 | 17 | DigitalOut led(PC_0); |
leandropg | 0:4265ec26da85 | 18 | |
lucaVisconti | 1:1bd5272d7a1f | 19 | |
lucaVisconti | 1:1bd5272d7a1f | 20 | //Define an input port for each command |
lucaVisconti | 10:4ff4a376a6fd | 21 | DigitalIn pushButton1(PC_1); //connect "SOURCE" steering wheel controls button to STMF401RE PC_1 port |
lucaVisconti | 10:4ff4a376a6fd | 22 | DigitalIn pushButton2(PC_2); //connect "TEL" steering wheel controls button to STMF401RE PC_2 port |
lucaVisconti | 10:4ff4a376a6fd | 23 | DigitalIn pushButton3(PC_3); //connect "VOLUP" steering wheel controls button to STMF401RE PC_3 port |
lucaVisconti | 10:4ff4a376a6fd | 24 | DigitalIn pushButton4(PC_4); //connect "VOLDWN" steering wheel controls button to STMF401RE PC_4 port |
lucaVisconti | 10:4ff4a376a6fd | 25 | DigitalIn pushButton5(PC_5); //connect "FF" steering wheel controls button to STMF401RE PC_5 port |
lucaVisconti | 10:4ff4a376a6fd | 26 | DigitalIn pushButton6(PC_6); //connect "RR" steering wheel controls button to STMF401RE PC_6 port |
lucaVisconti | 10:4ff4a376a6fd | 27 | DigitalIn pushButton7(PC_7); //connect "ROTUP" steering wheel controls button to STMF401RE PC_7 port |
lucaVisconti | 10:4ff4a376a6fd | 28 | DigitalIn pushButton8(PC_8); //connect "ROTDWN" steering wheel controls button to STMF401RE PC_8 port |
lucaVisconti | 10:4ff4a376a6fd | 29 | |
lucaVisconti | 1:1bd5272d7a1f | 30 | |
lucaVisconti | 1:1bd5272d7a1f | 31 | //int x; |
leandropg | 0:4265ec26da85 | 32 | |
leandropg | 0:4265ec26da85 | 33 | // Main Loop runs in its own thread in the OS |
leandropg | 0:4265ec26da85 | 34 | int main() { |
leandropg | 0:4265ec26da85 | 35 | |
leandropg | 0:4265ec26da85 | 36 | // Active Pull-Up Resistor |
lucaVisconti | 1:1bd5272d7a1f | 37 | pushButton1.mode(PullDown); |
lucaVisconti | 1:1bd5272d7a1f | 38 | pushButton2.mode(PullDown); |
lucaVisconti | 10:4ff4a376a6fd | 39 | pushButton3.mode(PullDown); |
lucaVisconti | 10:4ff4a376a6fd | 40 | pushButton4.mode(PullDown); |
lucaVisconti | 10:4ff4a376a6fd | 41 | pushButton5.mode(PullDown); |
lucaVisconti | 10:4ff4a376a6fd | 42 | pushButton6.mode(PullDown); |
lucaVisconti | 10:4ff4a376a6fd | 43 | pushButton7.mode(PullDown); |
lucaVisconti | 10:4ff4a376a6fd | 44 | pushButton8.mode(PullDown); |
leandropg | 0:4265ec26da85 | 45 | // Inifite Loop |
lucaVisconti | 1:1bd5272d7a1f | 46 | |
lucaVisconti | 1:1bd5272d7a1f | 47 | while(1) { |
lucaVisconti | 1:1bd5272d7a1f | 48 | |
lucaVisconti | 1:1bd5272d7a1f | 49 | // DEFINE for each button pressed which is the array to send |
lucaVisconti | 9:33d8b36e81d4 | 50 | int ARRAY_SEND[67]; |
lucaVisconti | 3:82270ac03cb7 | 51 | int i; |
lucaVisconti | 9:33d8b36e81d4 | 52 | if(pushButton1 == 1) { for (i=0;i<67;i++) {ARRAY_SEND[i]=ARRAY_SOURCE[i];} } |
lucaVisconti | 9:33d8b36e81d4 | 53 | else if(pushButton2 == 1) { for (i=0;i<67;i++) {ARRAY_SEND[i]=ARRAY_TEL[i];} } |
lucaVisconti | 10:4ff4a376a6fd | 54 | else if(pushButton3 == 1) { for (i=0;i<67;i++) {ARRAY_SEND[i]=ARRAY_VOLUP[i];} } |
lucaVisconti | 10:4ff4a376a6fd | 55 | else if(pushButton4 == 1) { for (i=0;i<67;i++) {ARRAY_SEND[i]=ARRAY_VOLDWN[i];} } |
lucaVisconti | 10:4ff4a376a6fd | 56 | else if(pushButton5 == 1) { for (i=0;i<67;i++) {ARRAY_SEND[i]=ARRAY_FF[i];} } |
lucaVisconti | 10:4ff4a376a6fd | 57 | else if(pushButton6 == 1) { for (i=0;i<67;i++) {ARRAY_SEND[i]=ARRAY_RR[i];} } |
lucaVisconti | 10:4ff4a376a6fd | 58 | else if(pushButton7 == 1) { for (i=0;i<67;i++) {ARRAY_SEND[i]=ARRAY_ROTUP[i];} } |
lucaVisconti | 10:4ff4a376a6fd | 59 | else if(pushButton8 == 1) { for (i=0;i<67;i++) {ARRAY_SEND[i]=ARRAY_ROTDWN[i];} } |
lucaVisconti | 10:4ff4a376a6fd | 60 | // IF any button is pressed the outputs level is 0 |
lucaVisconti | 10:4ff4a376a6fd | 61 | else { |
lucaVisconti | 1:1bd5272d7a1f | 62 | // LEDs Turn-Off |
leandropg | 0:4265ec26da85 | 63 | led = 0; |
lucaVisconti | 1:1bd5272d7a1f | 64 | myled =0; |
leandropg | 0:4265ec26da85 | 65 | } |
lucaVisconti | 10:4ff4a376a6fd | 66 | //If a button is 1 CREATE A IRPULSE WAVEFORM THAT FOLLOW THE ARRAY_SEND |
lucaVisconti | 10:4ff4a376a6fd | 67 | if (pushButton1==1 || pushButton2 ==1 || pushButton3 ==1 || pushButton4 ==1 || pushButton5 ==1 || pushButton6 ==1 || pushButton7 ==1 || pushButton8 ==1 ) { |
lucaVisconti | 6:69152576b147 | 68 | //From BIT 0 to the final BIT OF ARRAYSEND |
lucaVisconti | 10:4ff4a376a6fd | 69 | int BIT,n; |
lucaVisconti | 9:33d8b36e81d4 | 70 | for (BIT = 0; BIT < 67; BIT ++) { |
lucaVisconti | 10:4ff4a376a6fd | 71 | //if the position of BIT in ARRAYSEND is even, turn on/off the IRLED and BOARD LED following a 38000Hz modulation(13usON/13usOFF) for a number of cicles = BIT value |
lucaVisconti | 10:4ff4a376a6fd | 72 | if ( BIT % 2==0) { |
lucaVisconti | 10:4ff4a376a6fd | 73 | for (n =1; n <= ARRAY_SEND[BIT]; n++){ |
lucaVisconti | 1:1bd5272d7a1f | 74 | myled =1; |
lucaVisconti | 10:4ff4a376a6fd | 75 | led =1; |
lucaVisconti | 10:4ff4a376a6fd | 76 | wait_us (13); |
lucaVisconti | 10:4ff4a376a6fd | 77 | myled =0; |
lucaVisconti | 10:4ff4a376a6fd | 78 | led =0; |
lucaVisconti | 10:4ff4a376a6fd | 79 | wait_us (13); |
lucaVisconti | 10:4ff4a376a6fd | 80 | }} |
lucaVisconti | 10:4ff4a376a6fd | 81 | //if the position of BIT in ARRAYSEND is odd, turn off the IRLED and BOARD LED following a 38000Hz modulation(13us+13us=26us OFF) for a number of cicles = BIT value |
lucaVisconti | 10:4ff4a376a6fd | 82 | else { |
lucaVisconti | 10:4ff4a376a6fd | 83 | for (n =1; n <= ARRAY_SEND[BIT]; n++){ |
lucaVisconti | 1:1bd5272d7a1f | 84 | myled =0; |
lucaVisconti | 10:4ff4a376a6fd | 85 | led =0; |
lucaVisconti | 10:4ff4a376a6fd | 86 | wait_us (26); |
lucaVisconti | 10:4ff4a376a6fd | 87 | }} |
lucaVisconti | 10:4ff4a376a6fd | 88 | } // end for |
lucaVisconti | 10:4ff4a376a6fd | 89 | //PUT 100000us OFF at the end of ARRAY_SEND IRPULSE WAVEFORM |
lucaVisconti | 9:33d8b36e81d4 | 90 | myled =0; |
lucaVisconti | 10:4ff4a376a6fd | 91 | led =0; |
lucaVisconti | 10:4ff4a376a6fd | 92 | wait_us (110000); |
lucaVisconti | 10:4ff4a376a6fd | 93 | } // end if |
lucaVisconti | 10:4ff4a376a6fd | 94 | } //end while |
lucaVisconti | 10:4ff4a376a6fd | 95 | } //end main |