code for sterring wheel interface

Dependencies:   MBC002-DigitalIn

Committer:
lucaVisconti
Date:
Wed Jun 27 08:36:52 2018 +0000
Revision:
1:1bd5272d7a1f
Parent:
0:4265ec26da85
Child:
2:7c5890e1af90
toenzo

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 1:1bd5272d7a1f 4 short ARRAY_SOURCE[] = {10,5,10,5,10,5,10,5,};
lucaVisconti 1:1bd5272d7a1f 5 short ARRAY_TEL[] = {5,10,5,10,5,10,5,10,};
lucaVisconti 1:1bd5272d7a1f 6
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 1:1bd5272d7a1f 43 int ARRAY_SEND;
lucaVisconti 1:1bd5272d7a1f 44
lucaVisconti 1:1bd5272d7a1f 45 if(pushButton1 == 1) {int ARRAY_SEND[] = ARRAY_SOURCE;}
lucaVisconti 1:1bd5272d7a1f 46 else if(pushButton2 == 1) {int ARRAY_SEND[] = ARRAY_TEL;}
lucaVisconti 1:1bd5272d7a1f 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 1:1bd5272d7a1f 53
lucaVisconti 1:1bd5272d7a1f 54 // ASSIGN to a variable the size of ARRAYSEND
lucaVisconti 1:1bd5272d7a1f 55 int BITS = sizeof (ARRAY_SEND)
lucaVisconti 1:1bd5272d7a1f 56
lucaVisconti 1:1bd5272d7a1f 57 //From BIT 0 of ARRAY_SEND to the final BIT OF ARRAYSEND
lucaVisconti 1:1bd5272d7a1f 58 for (BIT = 0; i < BITS; i ++) {
lucaVisconti 1:1bd5272d7a1f 59 //if the position of bit is even turn on the leds for bit value time,
lucaVisconti 1:1bd5272d7a1f 60 //if bit is odd turn off the leds for bit value time
lucaVisconti 1:1bd5272d7a1f 61 if (sizeof (ARRAY_SEND[BIT] % 2==0)) {
lucaVisconti 1:1bd5272d7a1f 62 myled =1;
lucaVisconti 1:1bd5272d7a1f 63 led =1;
lucaVisconti 1:1bd5272d7a1f 64 wait (BIT);}
lucaVisconti 1:1bd5272d7a1f 65 else {
lucaVisconti 1:1bd5272d7a1f 66 myled =0;
lucaVisconti 1:1bd5272d7a1f 67 led =0;
lucaVisconti 1:1bd5272d7a1f 68 wait (BIT);}
lucaVisconti 1:1bd5272d7a1f 69 }}