
Sparkfun Analog Joystick Test Program
Dependencies: 4DGL-uLCD-SE SparkfunAnalogJoystick mbed
Fork of Lab4 by
main.cpp
00001 #include "mbed.h" 00002 #include "SparkfunAnalogJoystick.h" 00003 #include "uLCD_4DGL.h" 00004 00005 #define M_PI 3.14159265358979323846 00006 00007 SparkfunAnalogJoystick joysttick(p18, p19, p20); 00008 uLCD_4DGL lcd(p13, p14, p15); 00009 00010 // Test program for the library 00011 // It would output all data about the joystick 00012 // It would also draw a compass to indicate the joystick status on the LCD display 00013 00014 int main() { 00015 lcd.baudrate(3000000); 00016 lcd.background_color(0); 00017 lcd.cls(); 00018 float lastx=0; 00019 float lasty=0; 00020 while(1) { 00021 printf("X-Axis: %f\n\r", joysttick.xAxis()); 00022 printf("Y-Axis: %f\n\r", joysttick.yAxis()); 00023 printf("Angle: %f\n\r", joysttick.angle()); 00024 printf("Distance: %f\n\r", joysttick.distance()); 00025 printf("Button: %d\n\r\n", joysttick.button()); 00026 float distance=joysttick.distance(); 00027 float angle=joysttick.angle(); 00028 float x=distance*cos(angle*M_PI/180)*40; 00029 float y=distance*sin(angle*M_PI/180)*40; 00030 printf("y: %f\n\r\n", y); 00031 lcd.circle(60, 60, 40, WHITE); 00032 lcd.line(60, 60, 60+lastx, 60-lasty, BLACK); 00033 lcd.line(60, 60, 60+x, 60-y, WHITE); 00034 lastx=x; 00035 lasty=y; 00036 wait(0.1); 00037 } 00038 }
Generated on Wed Jul 20 2022 08:49:29 by
