#include <FastLED.h>
const CRGB SKY = CRGB(20, 10, 210);
const CRGB GRASS = CRGB(20, 210, 10);
const CRGB DOT = CRGB(255, 10, 20);
const CRGB BUSH = CRGB(120, 255, 100);
const int BUTTON_PIN = 16;
const int LED_PIN = 5;
const int DOT_GROUND = 41;
const int FIRST_LED_GRASS = 48;
const int NUM_LEDS = 64;
const int ROW_LENGTH = 8;
const int BUSH_START = 47;
const int DOT_ROW_START = 40;
const int JUMP_LENGTH = 3;
int bushPos = BUSH_START;
int jumpFrame = 0;
int pressFrames = 0;
CRGB leds[NUM_LEDS];
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(BUTTON_PIN, INPUT_PULLUP);
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(210);
for(int i=0; i<FIRST_LED_GRASS; i++){
leds[i] = SKY;
}
for(int i=FIRST_LED_GRASS; i<NUM_LEDS; i++){
leds[i] = GRASS;
}
}
void loop() {
Serial.println(digitalRead((BUTTON_PIN)));
checkBush();
leds[DOT_GROUND] = DOT;
bool pressed = justPressed()
if(jumpFrame == 0 && pressed) {
jumpFrame = JUMP_LENGTH;
}
if(jumpFrame > 0){
leds[DOT_GROUND] = SKY;
leds[DOT_GROUND-ROW_LENGTH] = DOT;
}
else {
leds[DOT_GROUND-ROW_LENGTH] = SKY;
leds[DOT_GROUND] = DOT;
}
if (bushPos >= DOT_ROW_START && bushPos < FIRST_LED_GRASS) {
leds[bushPos] = BUSH;
}
int prev;
if(bushPos == BUSH_START){
prev = DOT_ROW_START;
}
else {
prev = bushPos + 1;
}
if (prev < FIRST_LED_GRASS) {
leds[prev] = SKY;
}
if(bushPos == DOT_GROUND && jumpFrame == 0){
fill_solid(leds, NUM_LEDS, CRGB::Red);
}
Serial.println(jumpFrame);
FastLED.show();
delay(100); // this speeds up the simulation
bushPos--;
if(jumpFrame > 0) {
jumpFrame--;
}
}
void checkBush()
{
if(bushPos == BUSH_START - ROW_LENGTH) {
bushPos = BUSH_START;
}
}
bool justPressed()
{
if(digitalRead((BUTTON_PIN)) == LOW){
pressFrames++;
}
else{
pressFrames = 0;
}
return pressFrames == 1; //if pressFrames is 1, the answer is true, otherwisse is false
}