Skip to content

Instantly share code, notes, and snippets.

@michaelsarduino
Created February 27, 2016 20:46
Show Gist options
  • Save michaelsarduino/8bce5f4c104d81fa23be to your computer and use it in GitHub Desktop.
Save michaelsarduino/8bce5f4c104d81fa23be to your computer and use it in GitHub Desktop.
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 16
static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000000, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000011, B11100000,
B11110011, B11100000,
B11111110, B11111000,
B01111110, B11111111,
B00110011, B10011111,
B00011111, B11111100,
B00001101, B01110000,
B00011011, B10100000,
B00111111, B11100000,
B00111111, B11110000,
B01111100, B11110000,
B01110000, B01110000,
B00000000, B00110000 };
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
int punkte = 0;
void setup() {
unsigned long beginn = millis();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
Serial.begin(9600);
while((millis() - beginn) < 30000)
{
int zufall = random(1, 5);
Serial.println(zufall);
switch (zufall)
{
case 1:
display.fillRect(0, 0, 64, 32, WHITE);
break;
case 2:
display.fillRect(64, 0, 64, 32, WHITE);
break;
case 3:
display.fillRect(0, 32, 64, 32, WHITE);
break;
case 4:
display.fillRect(64, 32, 64, 32, WHITE);
break;
}
display.display();
joystick(zufall);
display.clearDisplay();
punkte = punkte + 1;
}
display.clearDisplay();
display.setCursor(0,0);
display.setTextColor(WHITE);
display.setTextSize(2);
display.print("Score: ");
display.print(punkte);
display.display();
}
void loop() {
}
void joystick(int zufall)
{
int xAchse = analogRead(A0);
int yAchse = analogRead(A1);
if(zufall == 1)
{
while( !((xAchse > 511) && (yAchse < 511)) )
{
delay(50);
xAchse = analogRead(A0);
yAchse = analogRead(A1);
Serial.println("falsch");
}
}
if(zufall == 2)
{
while( !((xAchse > 511) && (yAchse > 511)) )
{
delay(50);
xAchse = analogRead(A0);
yAchse = analogRead(A1);
Serial.println("falsch");
}
}
if(zufall == 3)
{
while( !((xAchse < 511) && (yAchse < 511)) )
{
delay(50);
xAchse = analogRead(A0);
yAchse = analogRead(A1);
Serial.println("falsch");
}
}
if(zufall == 4)
{
while( !((xAchse < 511) && (yAchse > 511)) )
{
delay(50);
xAchse = analogRead(A0);
yAchse = analogRead(A1);
Serial.println("falsch");
}
}
Serial.println("richtig");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment