code for sterring wheel interface

Dependencies:   MBC002-DigitalIn

Committer:
lucaVisconti
Date:
Wed Jun 27 12:59:24 2018 +0000
Revision:
5:6dc69540b634
Parent:
4:faec61d0b6c0
Child:
6:69152576b147
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 1:1bd5272d7a1f 52
lucaVisconti 1:1bd5272d7a1f 53 // ASSIGN to a variable the size of ARRAYSEND
lucaVisconti 1:1bd5272d7a1f 54
lucaVisconti 1:1bd5272d7a1f 55 //From BIT 0 of ARRAY_SEND to the final BIT OF ARRAYSEND
lucaVisconti 3:82270ac03cb7 56 int BIT;
lucaVisconti 3:82270ac03cb7 57 for (BIT = 0; i < 8; i ++) {
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 2:7c5890e1af90 63 wait (ARRAY_SEND[BIT]);}
lucaVisconti 1:1bd5272d7a1f 64 else {
lucaVisconti 1:1bd5272d7a1f 65 myled =0;
lucaVisconti 1:1bd5272d7a1f 66 led =0;
lucaVisconti 2:7c5890e1af90 67 wait (ARRAY_SEND[BIT]);}
lucaVisconti 5:6dc69540b634 68 }}}