Week 7’s assignment was to create a device using I²C protocol. I decided to use an Arduino Nano because I was at work and did not have my ATtiny board. I connected the board to a 0.91 OLED screen on a I²C breakout. With some AI assistance, I was able to create a very very very very low fidelity version of Geometry Dash. After debugging, I scanned the signal on an oscilloscope. The square wave was there as expected, but interestingly there were some strange artifacts inside some wavelengths.
#include#include #include U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE); const int buttonPin = 2; int playerY = 24; int playerV = 0; bool jumping = false; bool gameOver = false; int obstacleX = 128; const int obstacleW = 6; const int obstacleH = 6; int groundY = 30; int score = 0; int topScore = 0; int nextGap = 0; unsigned long lastFrame = 0; const int frameDelay = 40; void setup() { pinMode(buttonPin, INPUT_PULLUP); randomSeed(analogRead(A0)); u8g2.begin(); u8g2.setFont(u8g2_font_5x8_tf); } void loop() { unsigned long now = millis(); if (now - lastFrame < frameDelay) return; lastFrame = now; if (digitalRead(buttonPin) == LOW && !jumping) { jumping = true; playerV = -6; } if (jumping) { playerY += playerV; playerV += 1; if (playerY >= 24) { playerY = 24; playerV = 0; jumping = false; } } obstacleX -= 3; if (obstacleX < -obstacleW - nextGap) { obstacleX = 128 + random(10, 40); nextGap = random(15, 60); score++; if (score > topScore) topScore = score; } bool hit = (obstacleX < 20 && obstacleX + obstacleW > 10 && playerY > 22); if (hit) { score = 0; obstacleX = 128; playerY = 24; playerV = 0; jumping = false; } u8g2.firstPage(); do { u8g2.drawHLine(0, groundY, 128); u8g2.drawBox(10, playerY, 6, 6); u8g2.drawBox(obstacleX, 24, obstacleW, obstacleH); u8g2.setCursor(0, 8); u8g2.print("Score:"); u8g2.print(score); u8g2.setCursor(70, 8); u8g2.print("Top:"); u8g2.print(topScore); } while (u8g2.nextPage()); }