updated to large led
This commit is contained in:
parent
a8a7222e03
commit
a88eab9ee5
4 changed files with 117 additions and 14 deletions
|
@ -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 */
|
||||
|
@ -141,7 +141,18 @@ 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++)
|
||||
|
||||
|
||||
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);*/
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
33
VSCode/Pong/src/Pong.cpp
Normal file
33
VSCode/Pong/src/Pong.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include <Arduino.h>
|
||||
|
||||
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.
|
||||
*/
|
|
@ -1,4 +1,5 @@
|
|||
#include <Arduino.h>
|
||||
#include <Adafruit_WS2801.h>
|
||||
|
||||
/**
|
||||
* Player 1: x = 0
|
||||
|
@ -47,15 +48,17 @@
|
|||
#define GAME_STATE_RUNNING 1
|
||||
#define GAME_STATE_END 2
|
||||
#define GAME_STATE_INIT 3
|
||||
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
|
||||
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 <Arduino.h>
|
||||
|
||||
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<X_MAX*Y_MAX; i++) {
|
||||
pixels.setPixelColor(i, pixels.Color(0, 0, 0));
|
||||
pixels.setPixelColor(i, 0, 0, 0);
|
||||
}
|
||||
pixels.show();
|
||||
}
|
||||
|
||||
void toggleLed(byte x, byte y, byte type)
|
||||
{
|
||||
byte ledIndex = y * X_MAX + x;
|
||||
byte ledIndex ;
|
||||
if(y%2 == 0)
|
||||
{
|
||||
ledIndex = y * X_MAX + x;
|
||||
}
|
||||
else
|
||||
{
|
||||
ledIndex = y * X_MAX + (X_MAX -x -1);
|
||||
}
|
||||
uint32_t color;
|
||||
|
||||
switch(type) {
|
||||
case LED_TYPE_PADDLE:
|
||||
color = pixels.Color(0, 8, 8);
|
||||
color = Color(0, 8, 8);
|
||||
break;
|
||||
case LED_TYPE_BALL_RED:
|
||||
color = pixels.Color(12, 0, 0);
|
||||
color = Color(12, 0, 0);
|
||||
break;
|
||||
case LED_TYPE_BALL:
|
||||
color = pixels.Color(0, 10, 0);
|
||||
color = Color(0, 10, 0);
|
||||
break;
|
||||
case LED_TYPE_OFF:
|
||||
color = pixels.Color(0, 0, 0);
|
||||
color = Color(0, 0, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue