#include <Arduino.h>
#include "FastLED.h"
#define Vx A0 // Define / Equate "Vx" with A0, the pin where Vx is connected
#define Vy A1 // Define / Equate "Vy" with A1, the pin where Vy is connected
#define Button A2 // Define / Equate Button with A2, the pin where the button is connected
#define NUM_LEDS 64
#define DATA_PIN 2
CRGB leds[NUM_LEDS];
void setup() {
pinMode(Vx, INPUT); // Configure Vx (A0) as an Input
pinMode(Vy, INPUT); // Configure Vy (A1) as an Input
pinMode(Button, INPUT_PULLUP); // Configure Button (A2) as an Input, internally "pulled-up" to 5V
// Note, we're configuring an Analog input as digital input
// which is perfectly fine. I did this to make the wiring easier
// and keep all of the wires on the same side of the board
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(64);
Serial.begin(9600); // Initialize Serial Port at 9600 baud to display the results
}
void loop()
{
int x, y, btn;
x = analogRead(Vx); // Read the analog value of Vx (Analog Values are from 0-1023 which equate to 0V to 5V)
y = analogRead(Vy); // Read the analog value of Vy
btn = digitalRead(Button); // Read the button. When the button is open (unpushed),
// the input will read High (+5V)
// When the button is closed (pressed), the input pin
// is connected to ground and will read Low (0V)
/*Serial.print(x); // Print the X value to the serial port
Serial.print("\t"); // Print a Tab character
Serial.print(y); // Print the Y value
Serial.print("\t"); // Print a Tab
Serial.println(btn); // Print the value of the Btn (0=Pushed, 1 = Not Pushed)
delay(250); // Delay 250ms so the results don't print too quickly*/
if (x <= 80) {
FastLED.clear();
leds[3] = CRGB(255, 18, 0);
leds[4] = CRGB(255, 18, 0);
leds[11] = CRGB(255, 18, 0);
leds[12] = CRGB(255, 18, 0);
leds[19] = CRGB(255, 18, 0);
leds[20] = CRGB(255, 18, 0);
leds[24] = CRGB(255, 18, 0);
leds[27] = CRGB(255, 18, 0);
leds[28] = CRGB(255, 18, 0);
leds[31] = CRGB(255, 18, 0);
leds[32] = CRGB(255, 18, 0);
leds[33] = CRGB(255, 18, 0);
leds[35] = CRGB(255, 18, 0);
leds[36] = CRGB(255, 18, 0);
leds[38] = CRGB(255, 18, 0);
leds[39] = CRGB(255, 18, 0);
leds[41] = CRGB(255, 18, 0);
leds[42] = CRGB(255, 18, 0);
leds[43] = CRGB(255, 18, 0);
leds[44] = CRGB(255, 18, 0);
leds[45] = CRGB(255, 18, 0);
leds[46] = CRGB(255, 18, 0);
leds[50] = CRGB(255, 18, 0);
leds[51] = CRGB(255, 18, 0);
leds[52] = CRGB(255, 18, 0);
leds[53] = CRGB(255, 18, 0);
leds[59] = CRGB(255, 18, 0);
leds[60] = CRGB(255, 18, 0);
FastLED.show();
}
if (x >= 900) {
FastLED.clear();
leds[3] = CRGB(255, 18, 0);
leds[4] = CRGB(255, 18, 0);
leds[10] = CRGB(255, 18, 0);
leds[11] = CRGB(255, 18, 0);
leds[12] = CRGB(255, 18, 0);
leds[13] = CRGB(255, 18, 0);
leds[17] = CRGB(255, 18, 0);
leds[18] = CRGB(255, 18, 0);
leds[19] = CRGB(255, 18, 0);
leds[20] = CRGB(255, 18, 0);
leds[21] = CRGB(255, 18, 0);
leds[22] = CRGB(255, 18, 0);
leds[24] = CRGB(255, 18, 0);
leds[25] = CRGB(255, 18, 0);
leds[27] = CRGB(255, 18, 0);
leds[28] = CRGB(255, 18, 0);
leds[30] = CRGB(255, 18, 0);
leds[31] = CRGB(255, 18, 0);
leds[32] = CRGB(255, 18, 0);
leds[35] = CRGB(255, 18, 0);
leds[36] = CRGB(255, 18, 0);
leds[39] = CRGB(255, 18, 0);
leds[43] = CRGB(255, 18, 0);
leds[44] = CRGB(255, 18, 0);
leds[51] = CRGB(255, 18, 0);
leds[52] = CRGB(255, 18, 0);
leds[59] = CRGB(255, 18, 0);
leds[60] = CRGB(255, 18, 0);
FastLED.show();
}
if (y <= 100) {
FastLED.clear();
fill_solid (leds, NUM_LEDS, CRGB(0, 255, 0));
FastLED.show();
}
if (y >= 900) {
FastLED.clear();
fill_solid (leds, NUM_LEDS, CRGB(255, 0, 0));
FastLED.show();
}
if (btn == 0) {
FastLED.clear();
FastLED.show();
}
}
Comments