2 buttons and 2 switches, compiles, not tested

Dependencies:   mbed C12832 MMA7660 USBDevice

main.cpp

Committer:
wojt86
Date:
2019-10-16
Revision:
13:d29eb4570e27
Parent:
12:b6a803a6450e

File content as of revision 13:d29eb4570e27:

#include "mbed.h"
#include "USBKeyboard.h"
#include "MMA7660.h"
#include "C12832.h"
 
MMA7660         Accelerometer (p28,p27);
 
USBKeyboard     Usbkeyboard;
C12832          LCD (p5,p7,p6,p8,p11);
BusOut   red_led(p12);
BusOut   yellow_led(p13);
BusOut   blue_led(p14);
BusOut   green_led(p15);
 
int main (void)
{
 
    float Acc_X = 0;
    float Acc_Y = 0;
    float Acc_Z = 0;
 
    while (true) {
 
        Acc_X = Accelerometer.x ();
        Acc_Y = Accelerometer.y ();
        Acc_Z = Accelerometer.z ();
 
        LCD.cls ();                         //LCD display showing the coordinates (turn off when submitting the program as only per programing
        LCD.locate (0,0);
        LCD.printf("X Axis: %f",Acc_X);
        LCD.locate (0,10);
        LCD.printf("Y Axis: %f",Acc_Y);
        LCD.locate (0,20);
        LCD.printf("Z Axis: %f",Acc_Z);
 
        wait (0.00000000001);
 
        if (Acc_Y>0.08) {                   //Y axis program
          
            Usbkeyboard.keyCode (UP_ARROW);
            red_led=1;
            yellow_led=0;
      
        } else if (Acc_Y<0.08) {
            //  Usbkeyboard.printf("s\0");
            Usbkeyboard.keyCode (DOWN_ARROW);
            red_led=0;
            yellow_led=1;
        
          } else if (Acc_Y<0.25) {
            //turn int (main);
            red_led=0;
            yellow_led=0;
           
           } else if (Acc_Y<-0.25) {
            //turn int (main);
            red_led=0;
            yellow_led=0;
           }
        if (Acc_X>0.08) {                   //X axis program
            //Usbkeyboard.printf("w\0");
            Usbkeyboard.keyCode (LEFT_ARROW);
            green_led=1;
            blue_led=0;
        } else if (Acc_X<0.08) {
            //Usbkeyboard.printf("s\0");
            Usbkeyboard.keyCode (RIGHT_ARROW);
            green_led=0;
            blue_led=1;
            
        } else if (Acc_X<0.9) {
            green_led=0;
            blue_led=0;
            
         } else if (Acc_X<-0.9) {
            green_led=0;
            blue_led=0;
            //turn int (main);
            }
        /*
        if (Acc_Z>1.5) {                   //Z axis program - work in progress
            Usbkeyboard.printf("w\0");
            //Usbkeyboard.keyCode (LEFT_ARROW);
        } elses if (Acc_Z<1.5) {
            Usbskeyboard.printf("s\0");
            //Ussbkeyboard.keyCode (RIGHT_ARROW);
        }
        */
 }
 }