Simple catch the dot game
Dependencies: FXOS8700 Hexi_KW40Z NeatGUI
Fork of Hexi_Bubble_Game by
Move your dot exactly over the middle of the random stationary dot (within the time limit) and the led will light and the Hexiwear will vibrate.
Diff: main.cpp
- Revision:
- 2:085d270789f7
- Parent:
- 1:9bbb606da2d0
--- a/main.cpp Fri Aug 26 12:24:29 2016 +0000 +++ b/main.cpp Fri Sep 23 19:01:10 2016 +0000 @@ -1,7 +1,28 @@ +//HexiGame.cpp +//R. Scott Coppersmith +//Build 23 September 2016 #include "mbed.h" #include <SSD1351_SPI.h> -#include <HexiBubble.h> +#include <HexiGame.h> #include "FXOS8700.h" +#include "Hexi_KW40Z.h" + +#define LED_ON 0 +#define LED_OFF 1 + +void StartHaptic(void); +void StopHaptic(void const *n); +AnalogIn analog(PTB2); +Serial pc(USBTX, USBRX); +unsigned int m_z = 22222; +unsigned int m_w = 98764; +unsigned int rgen (void) +{ + + m_z = 36969 * (m_z & 65535) + (m_z >>16); + m_w = 18000 * (m_w & 65535) + (m_w >>16); + return ((m_z <<16) + m_w); +} //SSD1351_SPI ( mosi, miso, sclk, cs, dc ) ; SSD1351_SPI OLED96x96(PTB22,PTB23,PTB21,PTB20,PTD15); @@ -13,17 +34,22 @@ DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut BOOSTEN(PTC13); //oled power enable +DigitalOut haptic(PTB9); int count = 0; int count2 = 0; +int count3 = 0; extern const uint8_t Main_screen_bmp[ 36864 ]; int argb = 0xff000000; int rgbd = 0x00000000; int xposg = 0; int yposg = 0; +int randx = 0; +int randy = 0; int main() { led1 = 1; led2 = 1; led3 = 1; + pc.printf("HexiGame \r\n"); // Configure Accelerometer FXOS8700 accel.accel_config(); BOOSTEN = 1; @@ -39,44 +65,59 @@ count=count+4; } } - OLED96x96.drawCircle(61,47,4,0xff00ff00); - OLED96x96.drawCircle(61,47,3,0xff00ff00); - OLED96x96.drawCircle(61,47,2,0xff00ff00); + Thread::wait(6000); while(1) { accel.acquire_accel_data_g(accel_data); - xposg=(accel_data[1]*(-40.0)); - if (xposg > 27) - xposg = 27; - if (xposg < -27) - xposg = -27; - yposg=accel_data[0]*40.0; - if (yposg > 27) - yposg = 27; - if (yposg < -27) - yposg = -27; - if((xposg == 0) and (yposg == 0)) - { - led1 = 1; - led2 = 0; - } - OLED96x96.drawCircle(61,47,8,0xff00ff00); - OLED96x96.drawLine(61,7,61,87,0xff00ff00); - OLED96x96.drawLine(21,47,101,47,0xff00ff00); + xposg=(accel_data[1]*(-50.0)); + if (xposg > 36) + xposg = 36; + if (xposg < -36) + xposg = -36; + yposg=accel_data[0]*50.0; + if (yposg > 36) + yposg = 36; + if (yposg < -36) + yposg = -36; + OLED96x96.drawCircle(61-xposg,47+yposg,5,0xff00ff00); OLED96x96.drawCircle(61-xposg,47+yposg,4,0xff00ff00); OLED96x96.drawCircle(61-xposg,47+yposg,3,0xff00ff00); - OLED96x96.drawCircle(61-xposg,47+yposg,2,0xff00ff00); - Thread::wait(20); + OLED96x96.drawCircle(61-xposg,47+yposg,2,0xff00ff00); + OLED96x96.drawCircle(61-xposg,47+yposg,1,0xff00ff00); + Thread::wait(10); + OLED96x96.drawCircle(61-xposg,47+yposg,5,0xff000000); OLED96x96.drawCircle(61-xposg,47+yposg,4,0xff000000); OLED96x96.drawCircle(61-xposg,47+yposg,3,0xff000000); OLED96x96.drawCircle(61-xposg,47+yposg,2,0xff000000); - led1 = 0; - led2 = 1; + OLED96x96.drawCircle(61-xposg,47+yposg,1,0xff000000); + if ((61-xposg == 40+randx) and (47+yposg == 40+randy)) + { + pc.printf("Hit!\r\n"); + led1 = LED_ON; + haptic = 1; + count3 = 0; + } + count3++; count2++; + if ((count3 > 20)and (haptic == 1)) + { + count2 = 101; + haptic = 0; + } if (count2 > 100) { //blank display to avoid image burn + haptic = 0; + count3 = 0; + led1 = LED_OFF; OLED96x96.fillRect(16,0,111,96,0xff000000);//alpha, BGR count2 = 0; + randx = rgen()%40; + pc.printf("randx = %d\r\n",randx); + randy = rgen()%40; + pc.printf("randy = %d\r\n",randy); + OLED96x96.drawCircle(40+randx,40+randy,3,0xffff00ff); + OLED96x96.drawCircle(40+randx,40+randy,2,0xffff00ff); + OLED96x96.drawCircle(40+randx,40+randy,1,0xff00ff00); } //BOOSTEN = 0; //turn off display after about 1 minute to avoid image burn }