diff --git a/VSCode/Matrix/Ping Pong/src/main.cpp b/VSCode/Matrix/Ping Pong/src/main.cpp index 0e0a0cc..2442aee 100755 --- a/VSCode/Matrix/Ping Pong/src/main.cpp +++ b/VSCode/Matrix/Ping Pong/src/main.cpp @@ -41,7 +41,7 @@ uint8_t clockPin = 3; // Green wire on Adafruit Pixels // Set the first variable to the NUMBER of pixels in a row and // the second value to number of pixels in a column. -Adafruit_WS2801 strip = Adafruit_WS2801((uint16_t)200, dataPin, clockPin); +Adafruit_WS2801 strip = Adafruit_WS2801((uint16_t)10, (uint16_t)20,dataPin, clockPin); /* Helper functions */ @@ -140,8 +140,19 @@ void setup() { void loop() { // Some example procedures showing how to display to the pixels //drawX(10, 20, 100); - //bounce(10, 20, 50); - for(uint8_t i; i<200; i++) + // bounce(10, 20, 50); + + + for( int i = 0; i<200; i++) + + { + + strip.setPixelColor(i,250,0,0); + + strip.show(); + } + strip.show(); + /*for(uint8_t i; i<200; i++) { strip.setPixelColor(i,255,0,0); @@ -162,6 +173,6 @@ void loop() { strip.setPixelColor(i,0,0,255); } strip.show(); - delay(5000); + delay(5000);*/ } diff --git a/VSCode/Pong/platformio.ini b/VSCode/Pong/platformio.ini index 4464928..4087342 100755 --- a/VSCode/Pong/platformio.ini +++ b/VSCode/Pong/platformio.ini @@ -10,6 +10,8 @@ [env:uno] platform = atmelavr -board = uno +board = nanoatmega328 framework = arduino -lib_deps = adafruit/Adafruit NeoPixel@^1.10.4 +lib_deps = + adafruit/Adafruit NeoPixel@^1.10.4 + adafruit/Adafruit WS2801 Library@^1.1.1 diff --git a/VSCode/Pong/src/Pong.cpp b/VSCode/Pong/src/Pong.cpp new file mode 100644 index 0000000..10ce5e7 --- /dev/null +++ b/VSCode/Pong/src/Pong.cpp @@ -0,0 +1,33 @@ +#include + +static uint32_t Color(uint8_t r, uint8_t g, uint8_t b) { + return ((uint32_t)r << 16) | ((uint32_t)g << 8) | b; + } + /*! + @brief Convert separate red, green, blue and white values into a + single "packed" 32-bit WRGB color. + @param r Red brightness, 0 to 255. + @param g Green brightness, 0 to 255. + @param b Blue brightness, 0 to 255. + @param w White brightness, 0 to 255. + @return 32-bit packed WRGB value, which can then be assigned to a + variable for later use or passed to the setPixelColor() + function. Packed WRGB format is predictable, regardless of + LED strand color order. + */ + static uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) { + return ((uint32_t)w << 24) | ((uint32_t)r << 16) | ((uint32_t)g << 8) | b; + } + static uint32_t ColorHSV(uint16_t hue, uint8_t sat = 255, uint8_t val = 255); + /*! + @brief A gamma-correction function for 32-bit packed RGB or WRGB + colors. Makes color transitions appear more perceptially + correct. + @param x 32-bit packed RGB or WRGB color. + @return Gamma-adjusted packed color, can then be passed in one of the + setPixelColor() functions. Like gamma8(), this uses a fixed + gamma correction exponent of 2.6, which seems reasonably okay + for average NeoPixels in average tasks. If you need finer + control you'll need to provide your own gamma-correction + function instead. + */ \ No newline at end of file diff --git a/VSCode/Pong/src/main.cpp b/VSCode/Pong/src/main.cpp index 95fc243..3a0454d 100755 --- a/VSCode/Pong/src/main.cpp +++ b/VSCode/Pong/src/main.cpp @@ -1,4 +1,5 @@ #include +#include /** * Player 1: x = 0 @@ -47,15 +48,17 @@ #define GAME_STATE_RUNNING 1 #define GAME_STATE_END 2 #define GAME_STATE_INIT 3 - #include +uint8_t dataPin = 6; +uint8_t clockPin = 3; + struct Coords { byte x; byte y; }; -Adafruit_NeoPixel pixels = Adafruit_NeoPixel(X_MAX * Y_MAX, PIN_LED_MATRIX, NEO_GRB + NEO_KHZ800); +Adafruit_WS2801 pixels = Adafruit_WS2801((uint16_t)10 ,(uint16_t)20, dataPin, clockPin ); bool buttonPressed = false; byte gameState; byte joystickPins[PLAYER_AMOUNT] = {PIN_JOYSTICK_1_Y, PIN_JOYSTICK_2_Y}; @@ -67,6 +70,51 @@ unsigned long lastDrawUpdate = 0; unsigned long lastBallUpdate = 0; unsigned long lastButtonClick = 0; +void resetLEDs(); +void initGame(); +void updateBall(); +void updateGame(); +boolean isButtonPressed(); +void playTone(byte type); +void toggleLed(byte x, byte y, byte type); +byte getPlayerMovement(byte playerId); +void endGame(); + +#include + +static uint32_t Color(uint8_t r, uint8_t g, uint8_t b) { + return ((uint32_t)r << 16) | ((uint32_t)g << 8) | b; + } + /*! + @brief Convert separate red, green, blue and white values into a + single "packed" 32-bit WRGB color. + @param r Red brightness, 0 to 255. + @param g Green brightness, 0 to 255. + @param b Blue brightness, 0 to 255. + @param w White brightness, 0 to 255. + @return 32-bit packed WRGB value, which can then be assigned to a + variable for later use or passed to the setPixelColor() + function. Packed WRGB format is predictable, regardless of + LED strand color order. + */ + static uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) { + return ((uint32_t)w << 24) | ((uint32_t)r << 16) | ((uint32_t)g << 8) | b; + } + static uint32_t ColorHSV(uint16_t hue, uint8_t sat = 255, uint8_t val = 255); + /*! + @brief A gamma-correction function for 32-bit packed RGB or WRGB + colors. Makes color transitions appear more perceptially + correct. + @param x 32-bit packed RGB or WRGB color. + @return Gamma-adjusted packed color, can then be passed in one of the + setPixelColor() functions. Like gamma8(), this uses a fixed + gamma correction exponent of 2.6, which seems reasonably okay + for average NeoPixels in average tasks. If you need finer + control you'll need to provide your own gamma-correction + function instead. + */ + + void setup() { pinMode(PIN_JOYSTICK_1_Y, INPUT); @@ -80,6 +128,7 @@ void setup() void loop() { + switch(gameState) { case GAME_STATE_INIT: initGame(); @@ -255,28 +304,36 @@ bool isButtonPressed() void resetLEDs() { for(byte i=0; i