fork download
  1. // Count elements in array
  2. #define COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
  3.  
  4. #include <Arduboy2.h>
  5.  
  6. // make an instance of arduboy used for many functions
  7. Arduboy2 arduboy;
  8.  
  9. class ball{
  10. public:
  11. int angle = 0;
  12. float x = 64;
  13. float y = 32;
  14. float spd = 0;
  15. int radius = 5;
  16. };
  17.  
  18. long prevMillis;
  19. long lastPressedButton;
  20.  
  21. ball *balls;
  22. int ballCount = 3;
  23.  
  24. // This function runs once in your game.
  25. // use it for anything that needs to be set only once in your game.
  26. void setup() {
  27.  
  28. randomSeed(analogRead(A3));
  29. balls = new ball[ ballCount ];
  30.  
  31. for(int i=0; i<ballCount; i++){
  32. balls[i].angle = random(0,360);
  33. balls[i].spd = random(1,5);
  34. }
  35.  
  36. // initiate arduboy instance
  37. arduboy.begin();
  38.  
  39. // here we set the framerate to 15, we do not need to run at
  40. // default 60 and it saves us battery life
  41. arduboy.setFrameRate(60);
  42. }
  43.  
  44. // our main game loop, this runs once every cycle/frame.
  45. // this is where our game logic goes.
  46. void loop() {
  47.  
  48. if (millis() > prevMillis+1000/60){
  49.  
  50. for(int i=0; i<ballCount; i++){
  51. balls[i].x = round(balls[i].x + cos(balls[i].angle*PI/180)*balls[i].spd);
  52. balls[i].y = round(balls[i].y + sin(balls[i].angle*PI/180)*balls[i].spd);
  53.  
  54. if(balls[i].x - balls[i].radius < 0 || balls[i].x + balls[i].radius > 128){
  55. balls[i].angle = 180-balls[i].angle;
  56. }
  57.  
  58. if (balls[i].y - balls[i].radius < 0 || balls[i].y + balls[i].radius > 64){
  59. balls[i].angle *= -1;
  60. }
  61.  
  62. balls[i].angle %= 360;
  63. }
  64.  
  65. prevMillis = millis();
  66. }
  67.  
  68. // pause render until it's time for the next frame
  69. if (!(arduboy.nextFrame()))
  70. return;
  71.  
  72. // first we clear our screen to black
  73. arduboy.clear();
  74.  
  75. if(millis() > lastPressedButton + 50){
  76. if(arduboy.pressed(A_BUTTON)){
  77.  
  78. delete [] balls;
  79. ballCount += 1;
  80. balls = new ball[ballCount];
  81.  
  82. for(int i=0; i<ballCount; i++){
  83. balls[i].x = 64;
  84. balls[i].y = 32;
  85. balls[i].angle = random(0,360);
  86. balls[i].spd = random(1,5);
  87. }
  88. }
  89.  
  90. if(arduboy.pressed(B_BUTTON) ){
  91. if(ballCount > 0){
  92. ballCount -= 1;
  93. }
  94. }
  95. lastPressedButton = millis();
  96. }
  97.  
  98. for(int i=0; i<ballCount; i++){
  99. arduboy.drawCircle(balls[i].x,balls[i].y,balls[i].radius,WHITE);
  100. }
  101.  
  102. arduboy.setCursor(4, 64-8);
  103. arduboy.print(F("Ball Count: "));
  104. arduboy.setCursor(4+64+4, 64-8);
  105. arduboy.print(ballCount);
  106. arduboy.setCursor(4+64+4+8+4, 64-8);
  107. arduboy.print("CPU: ");
  108. arduboy.setCursor(4+64+4+8+24+4, 64-8);
  109. arduboy.print(arduboy.cpuLoad());
  110.  
  111. // then we finaly we tell the arduboy to display what we just wrote to the display
  112. arduboy.display();
  113. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:4:22: fatal error: Arduboy2.h: No such file or directory
 #include <Arduboy2.h>
                      ^
compilation terminated.
stdout
Standard output is empty