for each button pressed nucleo sends a command, used to interface citroen steering wheel command to keenwood car radio

Dependencies:   MBC002-DigitalIn

Fork of steering_wheel_controls_TO_KEENWOOD_RADIO_INFRARED_INTERFACE by luca visconti

Revision:
1:1bd5272d7a1f
Parent:
0:4265ec26da85
Child:
2:7c5890e1af90
--- a/main.cpp	Sun May 20 11:33:50 2018 +0000
+++ b/main.cpp	Wed Jun 27 08:36:52 2018 +0000
@@ -1,51 +1,69 @@
-/**
- * MBC002 - DigitalIn
- * This example use the DigitalIn function
- * 20 May 2018 - Mbed Colombia - http://mbedcolombia.wordpress.com/
- *
- * Board: ST-Nucleo-F446RE - https://os.mbed.com/platforms/ST-Nucleo-F446RE/
- *
- * Copyright [2018] [Leandro Perez Guatibonza / leandropg AT gmail DOT com]
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *    http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
 #include "mbed.h"
 
-// LED connected Pin PC_0
+// DEFINE AN ARRAY FOR EACH COMMAND I NEED
+short ARRAY_SOURCE[] = {10,5,10,5,10,5,10,5,};
+short ARRAY_TEL[] = {5,10,5,10,5,10,5,10,};
+
+
+//DEFINE MY OUTPUTS "led" is IRLED connected on PC_0, "myled" is STM32 NUCLEO board-led
+DigitalOut myled(LED1);
 DigitalOut led(PC_0);
 
-// Push-Button connected Pin PC_3
-DigitalIn pushButton(PC_3);
+
+//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
-    pushButton.mode(PullUp);
+    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) {
-        
-        // Check Push-Button
-        if(pushButton == 0) {
-            
-            // LED Turn-On
-            led = 1;
+
+  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;
+
+       if(pushButton1 == 1)  {int ARRAY_SEND[] = ARRAY_SOURCE;}
+  else if(pushButton2 == 1)  {int ARRAY_SEND[] = ARRAY_TEL;}
+        else {
             
-        } else {
-            
-            // LED Turn-Off
+            // LEDs Turn-Off
             led = 0;
+            myled =0;            
         }
-    }
-}
\ No newline at end of file
+
+// ASSIGN to a variable the size of ARRAYSEND
+int BITS = sizeof (ARRAY_SEND)
+
+//From BIT 0 of ARRAY_SEND to the final BIT OF ARRAYSEND
+for (BIT = 0; i < BITS; i ++) {
+//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 (sizeof (ARRAY_SEND[BIT] % 2==0)) {           
+             myled =1;
+              led =1;
+             wait (BIT);}
+ else {            
+             myled =0;
+              led =0;
+             wait (BIT);}
+ }}
\ No newline at end of file