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 11:55:19 2018 +0000
Revision:
7:e80a50f5b898
Parent:
6:69152576b147
Child:
8:f8a9b7dbf399
4enzo

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