I am doing a project using LEDs, but the code i have written for it won't upload to the board. I tried another example code (the blinker one) and it uploaded to the board. What could be the issue?
I am using the Seed Studio Grove beginner kit for arduino board and i am using these LEDs:
This is also my code:
#include <FastLED.h>
#define LED_PIN 6 // Pin connected to the data input of the LEDs
#define LED_COUNT 24 // Number of LEDs (one for each key)
#define DIAL_PIN A0 // Pin connected to the dial (potentiometer or rotary encoder)
#define CLOCK_PIN 7 // If using clocked WS2811 LEDs, define the clock pin
CRGB leds[LED_COUNT]; // Declare the LED array for FastLED
int dialValue = 0; // Variable to store the dial value
int previousDialValue = 0; // Variable to store the previous dial value
int currentMode = 0; // 0 - Chord mode, 1 - Twinkle Twinkle, 2 - Hot Cross Buns
unsigned long previousMillis = 0; // For timing the 2-second delay between notes
const long interval = 2000; // Interval (in ms) for note delay
void setup() {
FastLED.addLeds<WS2811, LED_PIN, GRB>(leds, LED_COUNT); // Use FastLED with WS2811 protocol
FastLED.setBrightness(100); // Set a brightness level (0-255)
Serial.begin(9600); // For debugging purposes
}
void loop() {
dialValue = analogRead(DIAL_PIN) / 42; // Map dial value to a mode (0-5)
// Check for dial change
if (dialValue != previousDialValue) {
previousDialValue = dialValue;
currentMode = dialValue; // Set the current mode based on dial position
resetLEDs(); // Reset all LEDs when switching modes
}
if (currentMode == 0) {
// Chord mode (example: C chord, D chord, etc.)
playChord();
} else if (currentMode == 1) {
// Song mode (Twinkle Twinkle)
playSongTwinkle();
} else if (currentMode == 2) {
// Hot Cross Buns
playSongHotCrossBuns();
}
delay(100); // Short delay for responsiveness
}
// Function to reset all LEDs to off
void resetLEDs() {
for (int i = 0; i < LED_COUNT; i++) {
leds[i] = CRGB::Black; // Turn off the LED
}
FastLED.show(); // Update the LED strip
}
// Function to simulate a chord (for teaching mode)
void playChord() {
// Chords: C, Dm, F, G
int chords[][3] = {
{0, 4, 7}, // C Major (C, E, G)
{2, 5, 9}, // D Minor (D, F, A)
{5, 9, 12}, // F Major (F, A, C)
{7, 11, 14} // G Major (G, B, D)
};
// Loop through each chord
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 3; j++) {
leds[chords[i][j]] = CRGB::Green; // Green for chord note
}
FastLED.show(); // Show the updated LED strip
delay(2000); // Wait for 2 seconds before turning off
resetLEDs(); // Reset the LEDs
}
}
// Function to play "Twinkle Twinkle" (Full Song)
void playSongTwinkle() {
// Full "Twinkle Twinkle Little Star" melody in C Major scale
int notes[] = {0, 0, 7, 7, 9, 9, 7, // Twinkle Twinkle
5, 5, 4, 4, 2, 2, 0, // Little Star
7, 7, 5, 5, 4, 4, 2, // How I wonder
7, 7, 5, 5, 4, 4, 2, // What you are
0, 0, 7, 7, 9, 9, 7, // Twinkle Twinkle
5, 5, 4, 4, 2, 2, 0}; // Little Star
int songLength = sizeof(notes) / sizeof(notes[0]);
for (int i = 0; i < songLength; i++) {
leds[notes[i]] = CRGB::Red; // Red for song note
FastLED.show(); // Show the updated LED strip
delay(2000); // Wait for 2 seconds before the next note
resetLEDs(); // Reset LEDs
delay(500); // Short pause between notes
}
}
// Function to play "Hot Cross Buns"
void playSongHotCrossBuns() {
// Full melody for "Hot Cross Buns" (E, D, C)
int notes[] = {4, 2, 0, 4, 2, 0, 4, 2, 0}; // E, D, C
int songLength = sizeof(notes) / sizeof(notes[0]);
for (int i = 0; i < songLength; i++) {
leds[notes[i]] = CRGB::Blue; // Blue for song note
FastLED.show(); // Show the updated LED strip
delay(2000); // Wait for 2 seconds before the next note
resetLEDs(); // Reset LEDs
delay(500); // Short pause between notes
}
}







