I pulled up my older version of the Love-O-Meter which doesnt use any sensors, but instead just outputs a random number as seen here:
//Random
#include "TrueRandom.h"
#include <TrueRandom.h>
//LED Strip
#include <Adafruit_NeoPixel.h>
#include "WS2812_Definitions.h"
#define LED 11
#define LED_COUNT 14
Adafruit_NeoPixel leds = Adafruit_NeoPixel(LED_COUNT, LED, NEO_GRB + NEO_KHZ800);
// mp3 includes
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SFEMP3Shield.h>
// touch includes
#include <MPR121.h>
#include <Wire.h>
#define MPR121_ADDR 0x5C
#define MPR121_INT 4
// mp3 variables
SFEMP3Shield MP3player;
byte result;
int lastPlayed = 0;
// sd card instantiation
SdFat sd;
long randNumber;
long ledCount;
void setup() {
Serial.begin(57600);
//LEDs
leds.begin();
clearLEDs();
leds.show();
//Pins
pinMode(A5, INPUT);
//digitalWrite(A5,);
pinMode(11, OUTPUT);
//Setup MP3 shield
if (!sd.begin(SD_SEL, SPI_HALF_SPEED)) sd.initErrorHalt();
if (!sd.chdir("/")) sd.errorHalt("sd.chdir");
MP3player.begin();
MP3player.setBitRate(192);
MP3player.setVolume(10, 10);
}
void loop() {
//LEDs will ride a rainbow slide to show that the Like-O-Meter is currently idling
for (int i = 0; i < LED_COUNT * 10; i++)
{
rainbow(i);
delay(100);
Serial.println(analogRead(A5));
//If both copper boards are touched and the circuit is complete
if (analogRead(A5) == 0)
beginCalculation();
}
}
//Function to print the compatibility and play certain music depending on the result
void beginCalculation()
{
//Play calculation music and cylon the LED strip to show that it is calculating the compatibility
MP3player.setVolume(40, 40);
MP3player.playTrack(0);
for (int i = 0; i < 2; i++)
{
cylon(INDIGO, 43);
}
//Print a random compatibility result
randNumber = TrueRandom.random(1, 15); // print a random number from 1 to 15
Serial.print("Random number is: ");
Serial.println(randNumber);
clearLEDs();
int rainbowScale = 192 / LED_COUNT;
for (int i = 0; i < randNumber; i++)
{
leds.setPixelColor(i, rainbowOrder((rainbowScale * i) % 192));
}
//Low Score
if (randNumber <= 5)
{
MP3player.setVolume(30, 30);
MP3player.playTrack(2);
}
//High Score
else if (randNumber >= 10)
{
MP3player.setVolume(80, 80);
MP3player.playTrack(1);
}
//Average Score
else
{
MP3player.setVolume(50, 50);
MP3player.playTrack(4);
}
leds.show();
delay(8500);
}
void clearLEDs()
{
for (int i = 0; i < LED_COUNT; i++)
{
leds.setPixelColor(i, 0);
}
}
void cylon(unsigned long color, byte wait)
{
// weight determines how much lighter the outer "eye" colors are
const byte weight = 4;
// It'll be easier to decrement each of these colors individually
// so we'll split them out of the 24-bit color value
byte red = (color & 0xFF0000) >> 16;
byte green = (color & 0x00FF00) >> 8;
byte blue = (color & 0x0000FF);
// Start at closest LED, and move to the outside
for (int i = 0; i <= LED_COUNT - 1; i++)
{
clearLEDs();
leds.setPixelColor(i, red, green, blue); // Set the bright middle eye
// Now set two eyes to each side to get progressively dimmer
for (int j = 1; j < 3; j++)
{
if (i - j >= 0)
leds.setPixelColor(i - j, red / (weight * j), green / (weight * j), blue / (weight * j));
if (i - j <= LED_COUNT)
leds.setPixelColor(i + j, red / (weight * j), green / (weight * j), blue / (weight * j));
}
leds.show(); // Turn the LEDs on
delay(wait); // Delay for visibility
}
// Now we go back to where we came. Do the same thing.
for (int i = LED_COUNT - 2; i >= 1; i--)
{
clearLEDs();
leds.setPixelColor(i, red, green, blue);
for (int j = 1; j < 3; j++)
{
if (i - j >= 0)
leds.setPixelColor(i - j, red / (weight * j), green / (weight * j), blue / (weight * j));
if (i - j <= LED_COUNT)
leds.setPixelColor(i + j, red / (weight * j), green / (weight * j), blue / (weight * j));
}
leds.show();
delay(wait);
}
}
void rainbow(byte startPosition)
{
// Need to scale our rainbow. We want a variety of colors, even if there
// are just 10 or so pixels.
int rainbowScale = 192 / LED_COUNT;
// Next we setup each pixel with the right color
for (int i = 0; i < LED_COUNT; i++)
{
// There are 192 total colors we can get out of the rainbowOrder function.
// It'll return a color between red->orange->green->...->violet for 0-191.
leds.setPixelColor(i, rainbowOrder((rainbowScale * (i + startPosition)) % 192));
}
// Finally, actually turn the LEDs on:
leds.show();
}
// Input a value 0 to 191 to get a color value.
// The colors are a transition red->yellow->green->aqua->blue->fuchsia->red...
// Adapted from Wheel function in the Adafruit_NeoPixel library example sketch
uint32_t rainbowOrder(byte position)
{
// 6 total zones of color change:
if (position < 31) // Red -> Yellow (Red = FF, blue = 0, green goes 00-FF)
{
return leds.Color(0xFF, position * 8, 0);
}
else if (position < 63) // Yellow -> Green (Green = FF, blue = 0, red goes FF->00)
{
position -= 31;
return leds.Color(0xFF - position * 8, 0xFF, 0);
}
else if (position < 95) // Green->Aqua (Green = FF, red = 0, blue goes 00->FF)
{
position -= 63;
return leds.Color(0, 0xFF, position * 8);
}
else if (position < 127) // Aqua->Blue (Blue = FF, red = 0, green goes FF->00)
{
position -= 95;
return leds.Color(0, 0xFF - position * 8, 0xFF);
}
else if (position < 159) // Blue->Fuchsia (Blue = FF, green = 0, red goes 00->FF)
{
position -= 127;
return leds.Color(position * 8, 0, 0xFF);
}
else //160 <position< 191 Fuchsia->Red (Red = FF, green = 0, blue goes FF->00)
{
position -= 159;
return leds.Color(0xFF, 0x00, 0xFF - position * 8);
}
}
// Cascades a single direction. One time.
void cascade(unsigned long color, byte direction, byte wait)
{
if (direction == TOP_DOWN)
{
for (int i = 0; i < LED_COUNT; i++)
{
clearLEDs(); // Turn off all LEDs
leds.setPixelColor(i, color); // Set just this one
leds.show();
delay(wait);
}
}
else
{
for (int i = LED_COUNT - 1; i >= 0; i--)
{
clearLEDs();
leds.setPixelColor(i, color);
leds.show();
delay(wait);
}
}
}
The lights and music in this code used to work. However, when I ran the code again today, it didnt work anymore. The led strip just stopped functioning.