code for sterring wheel interface

Dependencies:   MBC002-DigitalIn

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