code for sterring wheel interface

Dependencies:   MBC002-DigitalIn

main.cpp

Committer:
lucaVisconti
Date:
2018-06-29
Revision:
9:33d8b36e81d4
Parent:
8:f8a9b7dbf399
Child:
10:4ff4a376a6fd

File content as of revision 9:33d8b36e81d4:

#include "mbed.h"

// DEFINE AN ARRAY FOR EACH COMMAND I NEED

//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};
//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};

//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};
//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};

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};
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};

//DEFINE MY OUTPUTS "led" is IRLED connected on PC_0, "myled" is STM32 NUCLEO board-led
DigitalOut myled(LED1);
DigitalOut led(PC_0);


//Define an input port for each command
DigitalIn pushButton1(PC_1);
DigitalIn pushButton2(PC_2);
//DigitalIn pushButton3(PC_3);
//DigitalIn pushButton4(PC_4);
//DigitalIn pushButton5(PC_5);
//DigitalIn pushButton6(PC_6);
//DigitalIn pushButton7(PC_7);

//int x;

// Main Loop runs in its own thread in the OS
int main() {
   
    // Active Pull-Up Resistor
    pushButton1.mode(PullDown);
    pushButton2.mode(PullDown);
//    pushButton3.mode(PullDown);
//    pushButton4.mode(PullDown);
//    pushButton5.mode(PullDown);
//    pushButton6.mode(PullDown);
//    pushButton7.mode(PullDown);

   
    // Inifite Loop

  while(1) {

// DEFINE for each button pressed which is the array to send
// IF any button is pressed the outputs level is 0
int ARRAY_SEND[67];
int i;
 if(pushButton1 == 1)  { for (i=0;i<67;i++) {ARRAY_SEND[i]=ARRAY_SOURCE[i];} }
  else if(pushButton2 == 1)  { for (i=0;i<67;i++) {ARRAY_SEND[i]=ARRAY_TEL[i];} }
          else {
            
            // LEDs Turn-Off
            led = 0;
            myled =0;            
        }
//If a button is 1
if (pushButton1==1 || pushButton2 ==1 ) {
//From BIT 0 to the final BIT OF ARRAYSEND
int BIT;
for (BIT = 0; BIT < 67; BIT ++) {
//if the position of bit is even turn on the leds for bit value time, 
//if bit is odd turn off the leds for bit value time  
  if ( BIT % 2==0) {           
             myled =1;
              led =1;
             wait_us (ARRAY_SEND[BIT]);}
 
 else {            
             myled =0;
              led =0;
             wait_us (ARRAY_SEND[BIT]);}
             
             myled =0;
              led =0;
             wait_us (9000);
}}}}