/*
* RGBDuino test code - hope to implement a "true" RGBDuino board on the future.
*
* https://www.aliexpress.com/item/4000907154401.html
* https://github.com/RGBduino/RGBDuino/blob/master/RGBDuino%20Manual%20V1.1.pdf
* (use https://www.w3schools.com/colors/colors_groups.asp for wire colors)
*
* https://github.com/arduino12 11/12/2021
*/
#include <FastLED.h>
#include "notes.h"
#include "melody.h"
#define BUTTON_PIN (2)
#define SPEAKER_PIN (8)
#define RGB_LED_1_PIN (12)
#define RGB_LED_0_PIN (13)
#define RGB_LED_BRIGHTNESS (32) // 255 is very bright
const uint8_t LED_BAR_PINS[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
CRGB rgb_led_0;
CRGB rgb_led_1;
void play_melody(const uint16_t *melody)
{
uint16_t note, note_ms, note_1_32_ms = 7500 / *melody++;
while (1) {
note = *melody++;
if (note == NOTE_END)
break;
note_ms = note_1_32_ms * NOTE_BEAT_1_32[note >> NOTE_BEAT_BIT]; // duration
note &= NOTE_BEAT_MASK; // frequency
tone(SPEAKER_PIN, note);
delay(note_ms);
noTone(SPEAKER_PIN);
delay(note_1_32_ms * 2); // short note pause
if (!digitalRead(BUTTON_PIN))
break;
}
while (!digitalRead(BUTTON_PIN));
}
void setup()
{
pinMode(SPEAKER_PIN, OUTPUT);
for (uint8_t i = 0; i < sizeof(LED_BAR_PINS); i++)
pinMode(LED_BAR_PINS[i], OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP);
FastLED.addLeds<NEOPIXEL, RGB_LED_0_PIN>(&rgb_led_0, 1);
FastLED.addLeds<NEOPIXEL, RGB_LED_1_PIN>(&rgb_led_1, 1);
FastLED.setBrightness(RGB_LED_BRIGHTNESS);
rgb_led_0 = CRGB::Red;
rgb_led_1 = CRGB::Blue;
FastLED.show();
// delay(1000); // needed for simulation only because the first call to tone takes time to start
}
void loop()
{
// play_melody(MELODY_JINGLE_BELLS);
// play_melody(MELODY_HANUKKAH);
// play_melody(MELODY_HATIKVA);
// play_melody(MELODY_360_START);
play_melody(MELODY_360_GOOD);
play_melody(MELODY_360_BAD);
delay(1000);
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
bz1:1
bz1:2
rgb1:VDD
rgb1:DOUT
rgb1:VSS
rgb1:DIN
rgb2:VDD
rgb2:DOUT
rgb2:VSS
rgb2:DIN
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r
bargraph1:A1
bargraph1:A2
bargraph1:A3
bargraph1:A4
bargraph1:A5
bargraph1:A6
bargraph1:A7
bargraph1:A8
bargraph1:A9
bargraph1:A10
bargraph1:C1
bargraph1:C2
bargraph1:C3
bargraph1:C4
bargraph1:C5
bargraph1:C6
bargraph1:C7
bargraph1:C8
bargraph1:C9
bargraph1:C10
sw1:1
sw1:2
sw1:3
ring1:GND
ring1:VCC
ring1:DIN
ring1:DOUT
neopixels3:DOUT
neopixels3:VDD
neopixels3:VSS
neopixels3:DIN