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 luca visconti

Committer:
lucaVisconti
Date:
Thu Jun 28 13:40:21 2018 +0000
Revision:
8:f8a9b7dbf399
Parent:
7:e80a50f5b898
Child:
9:33d8b36e81d4
WIP STILL NOT WORKING!!!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
leandropg 0:4265ec26da85 1 #include "mbed.h"
leandropg 0:4265ec26da85 2
lucaVisconti 1:1bd5272d7a1f 3 // DEFINE AN ARRAY FOR EACH COMMAND I NEED
lucaVisconti 7:e80a50f5b898 4
lucaVisconti 8:f8a9b7dbf399 5 //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,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 8:f8a9b7dbf399 6 //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,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 8:f8a9b7dbf399 7
lucaVisconti 8:f8a9b7dbf399 8 int ARRAY_SOURCE[] = {9000,4500,560,1690,560,560,560,560,560,1690,560,1690,560,1690,560,560,560,1690,560,560,560,1690,560,1690,560,560,560,560,560,560,560,1690,560,560,560,560,560,560,560,1690,560,560,560,1690,560,560,560,560,560,560,560,1690,560,1690,560,560,560,1690,560,560,560,1690,560,1690,560,1690,560,26};
lucaVisconti 8:f8a9b7dbf399 9 int ARRAY_TEL[] = {9000,4500,560,1690,560,560,560,560,560,1690,560,1690,560,1690,560,560,560,1690,560,560,560,1690,560,1690,560,560,560,560,560,560,560,1690,560,560,560,560,560,560,560,1690,560,560,560,1690,560,560,560,560,560,560,560,1690,560,1690,560,560,560,1690,560,560,560,1690,560,1690,560,1690,560,26};
lucaVisconti 1:1bd5272d7a1f 10
lucaVisconti 1:1bd5272d7a1f 11 //DEFINE MY OUTPUTS "led" is IRLED connected on PC_0, "myled" is STM32 NUCLEO board-led
lucaVisconti 1:1bd5272d7a1f 12 DigitalOut myled(LED1);
leandropg 0:4265ec26da85 13 DigitalOut led(PC_0);
leandropg 0:4265ec26da85 14
lucaVisconti 1:1bd5272d7a1f 15
lucaVisconti 1:1bd5272d7a1f 16 //Define an input port for each command
lucaVisconti 1:1bd5272d7a1f 17 DigitalIn pushButton1(PC_1);
lucaVisconti 1:1bd5272d7a1f 18 DigitalIn pushButton2(PC_2);
lucaVisconti 1:1bd5272d7a1f 19 //DigitalIn pushButton3(PC_3);
lucaVisconti 1:1bd5272d7a1f 20 //DigitalIn pushButton4(PC_4);
lucaVisconti 1:1bd5272d7a1f 21 //DigitalIn pushButton5(PC_5);
lucaVisconti 1:1bd5272d7a1f 22 //DigitalIn pushButton6(PC_6);
lucaVisconti 1:1bd5272d7a1f 23 //DigitalIn pushButton7(PC_7);
lucaVisconti 1:1bd5272d7a1f 24
lucaVisconti 1:1bd5272d7a1f 25 //int x;
leandropg 0:4265ec26da85 26
leandropg 0:4265ec26da85 27 // Main Loop runs in its own thread in the OS
leandropg 0:4265ec26da85 28 int main() {
leandropg 0:4265ec26da85 29
leandropg 0:4265ec26da85 30 // Active Pull-Up Resistor
lucaVisconti 1:1bd5272d7a1f 31 pushButton1.mode(PullDown);
lucaVisconti 1:1bd5272d7a1f 32 pushButton2.mode(PullDown);
lucaVisconti 1:1bd5272d7a1f 33 // pushButton3.mode(PullDown);
lucaVisconti 1:1bd5272d7a1f 34 // pushButton4.mode(PullDown);
lucaVisconti 1:1bd5272d7a1f 35 // pushButton5.mode(PullDown);
lucaVisconti 1:1bd5272d7a1f 36 // pushButton6.mode(PullDown);
lucaVisconti 1:1bd5272d7a1f 37 // pushButton7.mode(PullDown);
lucaVisconti 1:1bd5272d7a1f 38
leandropg 0:4265ec26da85 39
leandropg 0:4265ec26da85 40 // Inifite Loop
lucaVisconti 1:1bd5272d7a1f 41
lucaVisconti 1:1bd5272d7a1f 42 while(1) {
lucaVisconti 1:1bd5272d7a1f 43
lucaVisconti 1:1bd5272d7a1f 44 // DEFINE for each button pressed which is the array to send
lucaVisconti 1:1bd5272d7a1f 45 // IF any button is pressed the outputs level is 0
lucaVisconti 7:e80a50f5b898 46 int ARRAY_SEND[68];
lucaVisconti 3:82270ac03cb7 47 int i;
lucaVisconti 7:e80a50f5b898 48 if(pushButton1 == 1) { for (i=0;i<68;i++) {ARRAY_SEND[i]=ARRAY_SOURCE[i];} }
lucaVisconti 7:e80a50f5b898 49 else if(pushButton2 == 1) { for (i=0;i<68;i++) {ARRAY_SEND[i]=ARRAY_TEL[i];} }
lucaVisconti 5:6dc69540b634 50 else {
leandropg 0:4265ec26da85 51
lucaVisconti 1:1bd5272d7a1f 52 // LEDs Turn-Off
leandropg 0:4265ec26da85 53 led = 0;
lucaVisconti 1:1bd5272d7a1f 54 myled =0;
leandropg 0:4265ec26da85 55 }
lucaVisconti 6:69152576b147 56 //If a button is 1
lucaVisconti 6:69152576b147 57 if (pushButton1==1 || pushButton2 ==1 ) {
lucaVisconti 6:69152576b147 58 //From BIT 0 to the final BIT OF ARRAYSEND
lucaVisconti 3:82270ac03cb7 59 int BIT;
lucaVisconti 7:e80a50f5b898 60 for (BIT = 0; BIT < 68; BIT ++) {
lucaVisconti 1:1bd5272d7a1f 61 //if the position of bit is even turn on the leds for bit value time,
lucaVisconti 1:1bd5272d7a1f 62 //if bit is odd turn off the leds for bit value time
lucaVisconti 3:82270ac03cb7 63 if ( BIT % 2==0) {
lucaVisconti 1:1bd5272d7a1f 64 myled =1;
lucaVisconti 1:1bd5272d7a1f 65 led =1;
lucaVisconti 8:f8a9b7dbf399 66 wait_us (ARRAY_SEND[BIT]);}
lucaVisconti 6:69152576b147 67
lucaVisconti 1:1bd5272d7a1f 68 else {
lucaVisconti 1:1bd5272d7a1f 69 myled =0;
lucaVisconti 1:1bd5272d7a1f 70 led =0;
lucaVisconti 8:f8a9b7dbf399 71 wait_us (ARRAY_SEND[BIT]);}
lucaVisconti 6:69152576b147 72 }}}}