Advertisement
Guest User

Untitled

a guest
May 14th, 2020
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. uint8_t packet[3];
  2.  
  3. static void formPacket(bool leftClick, bool rightClick, uint8_t x, uint8_t y)
  4. {
  5.   packet[0] = (1<<6) | (leftClick<<5) | (rightClick<<4);
  6.   packet[0] |= ((y>>6) & 0x3) << 2;
  7.   packet[0] |= ((x>>6) & 0x3);
  8.   packet[1] = x & 0x3F;
  9.   packet[2] = y & 0x3F;
  10. }
  11. void setup() {
  12.   Serial.begin(1200);
  13.   for(int i=0; i<200; i++)
  14.     Serial.write('M');
  15. }
  16.  
  17. int count=256;
  18. int pos=0;
  19. int d[][2]={
  20.   {1,0},
  21.   {0,1},
  22.   {-1,0},
  23.   {0,-1},
  24.   {0,0},  
  25. };
  26.  
  27. int Speed=8;
  28.  
  29. void loop() {
  30.   while(1)
  31.   {  
  32.     formPacket(0, 0, d[pos][0]*Speed, d[pos][1]*Speed);  
  33.     Serial.write(packet,3);
  34.     count-=Speed;
  35.     if(count<0)
  36.     {
  37.       count=200;
  38.       pos++;
  39.       if(d[pos][0]==0 && d[pos][1]==0)
  40.         pos=0;
  41.     }
  42.     Serial.flush();
  43.     delay(25);
  44.   }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement