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