code for sterring wheel interface

Dependencies:   MBC002-DigitalIn

Committer:
lucaVisconti
Date:
Wed Jun 27 11:33:57 2018 +0000
Revision:
3:82270ac03cb7
Parent:
2:7c5890e1af90
Child:
4:faec61d0b6c0
for Enzo
;

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
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 3:82270ac03cb7 44 int i;
lucaVisconti 3:82270ac03cb7 45 if(pushButton1 == 1) {for (i=0;i<8;i++){ARRAY_SEND[i]=ARRAY_SOURCE[i];}}
lucaVisconti 3:82270ac03cb7 46 else if(pushButton2 == 1) {for (i=0;i<8;i++){ARRAY_SEND[i]=ARRAY_TEL[i];}}
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
lucaVisconti 1:1bd5272d7a1f 56 //From BIT 0 of ARRAY_SEND to the final BIT OF ARRAYSEND
lucaVisconti 3:82270ac03cb7 57 int BIT;
lucaVisconti 3:82270ac03cb7 58 for (BIT = 0; i < 8; 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 3:82270ac03cb7 61 if ( BIT % 2==0) {
lucaVisconti 1:1bd5272d7a1f 62 myled =1;
lucaVisconti 1:1bd5272d7a1f 63 led =1;
lucaVisconti 2:7c5890e1af90 64 wait (ARRAY_SEND[BIT]);}
lucaVisconti 1:1bd5272d7a1f 65 else {
lucaVisconti 1:1bd5272d7a1f 66 myled =0;
lucaVisconti 1:1bd5272d7a1f 67 led =0;
lucaVisconti 2:7c5890e1af90 68 wait (ARRAY_SEND[BIT]);}
lucaVisconti 1:1bd5272d7a1f 69 }}