Interactive Device Design / Mbed 2 deprecated idd_hw3_dpcinci_FUJICAR

Dependencies:   DebounceIn USBDevice mbed

Fork of idd_hw3_dpcinci_FUJICAR by Dominic Cincione

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "USBMouse.h"
00003 #include "DebounceIn.h"
00004 
00005 //Serial pc(USBTX, USBRX);
00006 
00007 AnalogIn xAxis(A3);
00008 AnalogIn yAxis(A4);
00009 
00010 DebounceIn go(D4);
00011 
00012 
00013 DigitalOut led2(LED2);
00014 DigitalOut led1(LED1);
00015 DigitalOut led(LED3);
00016 
00017 float x = 0;
00018 float y = 0;
00019 
00020 float xStatic = 0.71;
00021 float yStatic = 0.71;
00022 
00023 int i = 50;
00024 
00025 uint8_t throttle;
00026 
00027 USBMouse mouse;
00028 
00029 
00030 int main() {
00031     
00032     xStatic = 0.7;
00033     yStatic = 0.7;
00034     
00035 
00036     while(i--){
00037         xStatic = xAxis.read();
00038         yStatic = yAxis.read();
00039         led = 0;
00040         
00041         wait(0.01);
00042         }
00043         
00044         led = 1;
00045     
00046 while(1) {
00047         
00048         throttle = !go.read();
00049         
00050         if(throttle==1){
00051             led2 = 0;
00052             led1 = 1;
00053             }
00054         if(throttle==0){
00055             led2 = 1;
00056             led1 = 0;
00057             }
00058         
00059         x = (xAxis.read()-xStatic)*50;
00060         y = (yAxis.read()-yStatic)*(-50);
00061         
00062         mouse.move(x,y);
00063          
00064         mouse.press(throttle);    
00065         
00066         /*        
00067         if(go == 0){
00068             G_led = 0;
00069             R_led = 1;
00070             }
00071             
00072         if(go==1){
00073             G_led = 1;
00074             R_led = 0;
00075             }
00076         */            
00077                     
00078         wait(0.01);    
00079             
00080     }
00081 }