Freedom Seeed Grove Joystick Example
Dependencies: mbed
Fork of frdm_Grove_Joystick_Example by
main.cpp
00001 #include "mbed.h" 00002 00003 AnalogIn xAxis(A0); 00004 AnalogIn yAxis(A1); 00005 00006 int x,y,button; // global variables to hold values 00007 Ticker joystick; // recurring interrupt to get joystick data 00008 00009 void joystick_Int_Handler() 00010 { 00011 x = xAxis.read() * 1000; // float (0->1) to int (0-1000) 00012 y = yAxis.read() * 1000; 00013 if ( (x > 900) || (y > 900) ) 00014 button = 1; 00015 else 00016 button = 0; 00017 } 00018 00019 int main() 00020 { 00021 // init interrupt, call every .2s 00022 joystick.attach(joystick_Int_Handler,0.2); 00023 00024 // Print out the variables 00025 while(1){ 00026 printf("\rX=%3d, Y=%3d, Button=%d",x,y,button); 00027 } 00028 }
Generated on Fri Jul 15 2022 21:45:21 by 1.7.2