I am, by no means, a software engineer. My code is crude at best, but it works
/* * Project Eros * CC-BY-SA Matthew Eargle * AirborneSurfer Productions * for element14 Presents * * airbornesurfer.com * element14.com/presents */ #include <Servo.h> Servo needle; // create servo object "needle" to move the needle // declare global variables const int numReadings = 10; int readings[numReadings]; // the readings from the analog input int readIndex = 0; // the index of the current reading int total = 0; // the running total int average = 0; // the average int meterPosition = 0; int needlePosition = 0; int readingMin = 1023; int readingMax = 0; int loveMatic = 1; int heart2 = 2; int hotStuff = 3; int fullHearts = 4; int meter9 = 5; int meter8 = 6; int meter7 = 7; int meter6 = 8; int meter5 = 9; int meter4 = 10; int meter3 = 11; int meter2 = 12; int meter1 = 13; int needlePin = 14; int brokenHeart = 16; int coldFish = 17; int heart1 = 18; int heart3 = 19; //int handlePin = 1; void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); // initialize all the readings to 0: for (int thisReading = 0; thisReading < numReadings; thisReading++) { readings[thisReading] = 0; } needle.write(70); // set pinmodes for input and output pinMode(needlePin, OUTPUT); pinMode(hotStuff, OUTPUT); pinMode(loveMatic, OUTPUT); pinMode(heart3, OUTPUT); pinMode(brokenHeart, OUTPUT); pinMode(meter1, OUTPUT); pinMode(meter2, OUTPUT); pinMode(meter3, OUTPUT); pinMode(meter4, OUTPUT); pinMode(meter5, OUTPUT); pinMode(meter6, OUTPUT); pinMode(meter7, OUTPUT); pinMode(meter8, OUTPUT); pinMode(meter9, OUTPUT); pinMode(fullHearts, OUTPUT); pinMode(coldFish, OUTPUT); pinMode(heart1, OUTPUT); pinMode(heart2, OUTPUT); // attach servo to Arduino needle.attach(needlePin); } void loop() { // read the sensor and show timer while (millis() < 10000) { if (millis() >= 9000 && millis() < 10000) { digitalWrite(meter9, LOW); digitalWrite(meter8, LOW); digitalWrite(meter7, LOW); digitalWrite(meter6, LOW); digitalWrite(meter5, LOW); digitalWrite(meter4, LOW); digitalWrite(meter3, LOW); digitalWrite(meter2, LOW); digitalWrite(meter1, LOW); digitalWrite(heart1, LOW); digitalWrite(heart2, LOW); digitalWrite(heart3, LOW); } else if (millis() >= 8000 && millis() < 9000) { digitalWrite(meter9, HIGH); digitalWrite(meter8, LOW); digitalWrite(meter7, LOW); digitalWrite(meter6, LOW); digitalWrite(meter5, LOW); digitalWrite(meter4, LOW); digitalWrite(meter3, LOW); digitalWrite(meter2, LOW); digitalWrite(meter1, LOW); digitalWrite(heart1, LOW); digitalWrite(heart2, LOW); digitalWrite(heart3, HIGH); delay(111); digitalWrite(heart1, LOW); digitalWrite(heart2, HIGH); digitalWrite(heart3, LOW); delay(111); digitalWrite(heart1, HIGH); digitalWrite(heart2, LOW); digitalWrite(heart3, LOW); delay(111); digitalWrite(heart1, LOW); digitalWrite(heart2, LOW); digitalWrite(heart3, HIGH); delay(111); digitalWrite(heart1, LOW); digitalWrite(heart2, HIGH); digitalWrite(heart3, LOW); delay(111); digitalWrite(heart1, HIGH); digitalWrite(heart2, LOW); digitalWrite(heart3, LOW); delay(111); digitalWrite(heart1, LOW); digitalWrite(heart2, LOW); digitalWrite(heart3, HIGH); delay(111); digitalWrite(heart1, LOW); digitalWrite(heart2, HIGH); digitalWrite(heart3, LOW); delay(111); digitalWrite(heart1, HIGH); digitalWrite(heart2, LOW); digitalWrite(heart3, LOW); delay(111); } else if (millis() >= 7000 && millis() < 8000) { digitalWrite(meter9, HIGH); digitalWrite(meter8, HIGH); digitalWrite(meter7, LOW); digitalWrite(meter6, LOW); digitalWrite(meter5, LOW); digitalWrite(meter4, LOW); digitalWrite(meter3, LOW); digitalWrite(meter2, LOW); digitalWrite(meter1, LOW); digitalWrite(heart1, LOW); digitalWrite(heart2, LOW); digitalWrite(heart3, HIGH); delay(111); digitalWrite(heart1, LOW); digitalWrite(heart2, HIGH); digitalWrite(heart3, LOW); delay(111); digitalWrite(heart1, HIGH); digitalWrite(heart2, LOW); digitalWrite(heart3, LOW); delay(111); digitalWrite(heart1, LOW); digitalWrite(heart2, LOW); digitalWrite(heart3, HIGH); delay(111); digitalWrite(heart1, LOW); digitalWrite(heart2, HIGH); digitalWrite(heart3, LOW); delay(111); digitalWrite(heart1, HIGH); digitalWrite(heart2, LOW); digitalWrite(heart3, LOW); delay(111); digitalWrite(heart1, LOW); digitalWrite(heart2, LOW); digitalWrite(heart3, HIGH); delay(111); digitalWrite(heart1, LOW); digitalWrite(heart2, HIGH); digitalWrite(heart3, LOW); delay(111); digitalWrite(heart1, HIGH); digitalWrite(heart2, LOW); digitalWrite(heart3, LOW); delay(111); } else if (millis() >= 6000 && millis() < 7000) { digitalWrite(meter9, HIGH); digitalWrite(meter8, HIGH); digitalWrite(meter7, HIGH); digitalWrite(meter6, LOW); digitalWrite(meter5, LOW); digitalWrite(meter4, LOW); digitalWrite(meter3, LOW); digitalWrite(meter2, LOW); digitalWrite(meter1, LOW); digitalWrite(heart1, LOW); digitalWrite(heart2, LOW); digitalWrite(heart3, HIGH); delay(333); digitalWrite(heart1, LOW); digitalWrite(heart2, HIGH); digitalWrite(heart3, LOW); delay(333); digitalWrite(heart1, HIGH); digitalWrite(heart2, LOW); digitalWrite(heart3, LOW); delay(333); } else if (millis() >= 5000 && millis() < 6000) { digitalWrite(meter9, HIGH); digitalWrite(meter8, HIGH); digitalWrite(meter7, HIGH); digitalWrite(meter6, HIGH); digitalWrite(meter5, LOW); digitalWrite(meter4, LOW); digitalWrite(meter3, LOW); digitalWrite(meter2, LOW); digitalWrite(meter1, LOW); digitalWrite(heart1, LOW); digitalWrite(heart2, LOW); digitalWrite(heart3, HIGH); delay(333); digitalWrite(heart1, LOW); digitalWrite(heart2, HIGH); digitalWrite(heart3, LOW); delay(333); digitalWrite(heart1, HIGH); digitalWrite(heart2, LOW); digitalWrite(heart3, LOW); delay(333); } else if (millis() >= 4000 && millis() < 5000) { digitalWrite(meter9, HIGH); digitalWrite(meter8, HIGH); digitalWrite(meter7, HIGH); digitalWrite(meter6, HIGH); digitalWrite(meter5, HIGH); digitalWrite(meter4, LOW); digitalWrite(meter3, LOW); digitalWrite(meter2, LOW); digitalWrite(meter1, LOW); digitalWrite(heart1, LOW); digitalWrite(heart2, LOW); digitalWrite(heart3, HIGH); delay(333); digitalWrite(heart1, LOW); digitalWrite(heart2, HIGH); digitalWrite(heart3, LOW); delay(333); digitalWrite(heart1, HIGH); digitalWrite(heart2, LOW); digitalWrite(heart3, LOW); delay(333); } else if (millis() >= 3000 && millis() < 4000) { digitalWrite(meter9, HIGH); digitalWrite(meter8, HIGH); digitalWrite(meter7, HIGH); digitalWrite(meter6, HIGH); digitalWrite(meter5, HIGH); digitalWrite(meter4, HIGH); digitalWrite(meter3, LOW); digitalWrite(meter2, LOW); digitalWrite(meter1, LOW); digitalWrite(heart1, LOW); digitalWrite(heart2, LOW); digitalWrite(heart3, HIGH); delay(333); digitalWrite(heart1, LOW); digitalWrite(heart2, HIGH); digitalWrite(heart3, LOW); delay(333); digitalWrite(heart1, HIGH); digitalWrite(heart2, LOW); digitalWrite(heart3, LOW); delay(333); } else if (millis() >= 2000 && millis() < 3000) { digitalWrite(meter9, HIGH); digitalWrite(meter8, HIGH); digitalWrite(meter7, HIGH); digitalWrite(meter6, HIGH); digitalWrite(meter5, HIGH); digitalWrite(meter4, HIGH); digitalWrite(meter3, HIGH); digitalWrite(meter2, LOW); digitalWrite(meter1, LOW); digitalWrite(heart1, LOW); digitalWrite(heart2, LOW); digitalWrite(heart3, HIGH); delay(333); digitalWrite(heart1, LOW); digitalWrite(heart2, HIGH); digitalWrite(heart3, LOW); delay(333); digitalWrite(heart1, HIGH); digitalWrite(heart2, LOW); digitalWrite(heart3, LOW); delay(333); } else if (millis() >= 1000 && millis() < 2000) { digitalWrite(meter9, HIGH); digitalWrite(meter8, HIGH); digitalWrite(meter7, HIGH); digitalWrite(meter6, HIGH); digitalWrite(meter5, HIGH); digitalWrite(meter4, HIGH); digitalWrite(meter3, HIGH); digitalWrite(meter2, HIGH); digitalWrite(meter1, LOW); digitalWrite(heart1, LOW); digitalWrite(heart2, LOW); digitalWrite(heart3, HIGH); delay(333); digitalWrite(heart1, LOW); digitalWrite(heart2, HIGH); digitalWrite(heart3, LOW); delay(333); digitalWrite(heart1, HIGH); digitalWrite(heart2, LOW); digitalWrite(heart3, LOW); delay(333); } else if (millis() >= 0 && millis() < 1000) { digitalWrite(meter9, HIGH); digitalWrite(meter8, HIGH); digitalWrite(meter7, HIGH); digitalWrite(meter6, HIGH); digitalWrite(meter5, HIGH); digitalWrite(meter4, HIGH); digitalWrite(meter3, HIGH); digitalWrite(meter2, HIGH); digitalWrite(meter1, HIGH); digitalWrite(heart1, LOW); digitalWrite(heart2, LOW); digitalWrite(heart3, HIGH); delay(333); digitalWrite(heart1, LOW); digitalWrite(heart2, HIGH); digitalWrite(heart3, LOW); delay(333); digitalWrite(heart1, HIGH); digitalWrite(heart2, LOW); digitalWrite(heart3, LOW); delay(333); } // take readings from the handles and find the average (adapted from "smoothing" example code) // subtract the last reading: total = total - readings[readIndex]; // read from the sensor: readings[readIndex] = analogRead(A1); // add the reading to the total: total = total + readings[readIndex]; // advance to the next position in the array: readIndex = readIndex + 1; // if we're at the end of the array... if (readIndex >= numReadings) { // ...wrap around to the beginning: readIndex = 0; } // calculate the average: average = total / numReadings; // send it to the computer as ASCII digits Serial.println(average); delay(1); // delay in between reads for stability } Serial.println("done!"); int reading = average; needlePosition = map(reading, 400, 1023, 120, 0); // scale meter value to use it with the servo (value between 0 and 180) meterPosition = map(reading, 400, 1023, 0, 10); // scale meter value for light meter (value between 0 and 10) meterPosition = constrain(meterPosition, 0, 10); Serial.println(meterPosition); needle.write(120); delay(200); finish(); } void finish() { switch (meterPosition) { case 0: while(true) { digitalWrite(brokenHeart, HIGH); digitalWrite(coldFish, LOW); delay(200); digitalWrite(brokenHeart, LOW); digitalWrite(coldFish, HIGH); needle.write(140); // sets the servo position according to the scaled value delay(200); } case 1: while(true) { digitalWrite(brokenHeart, HIGH); digitalWrite(coldFish, LOW); delay(200); digitalWrite(meter1, HIGH); digitalWrite(coldFish, HIGH); needle.write(needlePosition); // sets the servo position according to the scaled value delay(200); } case 2: digitalWrite(brokenHeart, HIGH); digitalWrite(meter1, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/2); delay(200); digitalWrite(meter2, HIGH); while(true) { digitalWrite(coldFish, HIGH); needle.write(needlePosition); delay(200); digitalWrite(coldFish, LOW); delay(200); } case 3: digitalWrite(brokenHeart, HIGH); digitalWrite(meter1, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/2); delay(200); digitalWrite(meter2, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/3); delay(200); digitalWrite(meter3, HIGH); while(true) { digitalWrite(coldFish, HIGH); needle.write(needlePosition); delay(200); digitalWrite(coldFish, LOW); delay(200); } case 4: digitalWrite(brokenHeart, HIGH); digitalWrite(meter1, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/2); delay(200); digitalWrite(meter2, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/3); delay(200); digitalWrite(meter3, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/4); delay(200); digitalWrite(meter4, HIGH); while(true) { digitalWrite(coldFish, HIGH); needle.write(needlePosition); delay(200); digitalWrite(coldFish, LOW); delay(200); } case 5: digitalWrite(brokenHeart, HIGH); digitalWrite(meter1, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/2); delay(200); digitalWrite(meter2, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/3); delay(200); digitalWrite(meter3, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/4); delay(200); digitalWrite(meter4, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/5); delay(200); digitalWrite(meter5, HIGH); while(true) { needle.write(needlePosition); } case 6: digitalWrite(brokenHeart, HIGH); digitalWrite(meter1, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/2); delay(200); digitalWrite(meter2, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/3); delay(200); digitalWrite(meter3, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/4); delay(200); digitalWrite(meter4, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/5); delay(200); digitalWrite(meter5, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/6); delay(200); digitalWrite(meter6, HIGH); while(true) { digitalWrite(hotStuff, HIGH); needle.write(needlePosition); delay(200); digitalWrite(hotStuff, LOW); delay(200); } case 7: digitalWrite(brokenHeart, HIGH); digitalWrite(meter1, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/2); delay(200); digitalWrite(meter2, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/3); delay(200); digitalWrite(meter3, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/4); delay(200); digitalWrite(meter4, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/5); delay(200); digitalWrite(meter5, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/6); delay(200); digitalWrite(meter6, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/7); delay(200); digitalWrite(meter7, HIGH); while(true) { digitalWrite(hotStuff, HIGH); needle.write(needlePosition); delay(200); digitalWrite(hotStuff, LOW); delay(200); } case 8: digitalWrite(brokenHeart, HIGH); digitalWrite(meter1, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/2); delay(200); digitalWrite(meter2, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/3); delay(200); digitalWrite(meter3, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/4); delay(200); digitalWrite(meter4, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/5); delay(200); digitalWrite(meter5, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/6); delay(200); digitalWrite(meter6, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/7); delay(200); digitalWrite(meter7, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/8); delay(200); digitalWrite(meter8, HIGH); while(true) { digitalWrite(hotStuff, HIGH); needle.write(needlePosition); delay(200); digitalWrite(hotStuff, LOW); delay(200); } case 9: digitalWrite(brokenHeart, HIGH); digitalWrite(meter1, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/2); delay(200); digitalWrite(meter2, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/3); delay(200); digitalWrite(meter3, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/4); delay(200); digitalWrite(meter4, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/5); delay(200); digitalWrite(meter5, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/6); delay(200); digitalWrite(meter6, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/7); delay(200); digitalWrite(meter7, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/8); delay(200); digitalWrite(meter8, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/9); delay(200); digitalWrite(meter9, HIGH); while(true) { digitalWrite(hotStuff, HIGH); needle.write(needlePosition); delay(200); digitalWrite(hotStuff, LOW); delay(200); } case 10: digitalWrite(brokenHeart, HIGH); digitalWrite(meter1, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/2); delay(200); digitalWrite(meter2, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/3); delay(200); digitalWrite(meter3, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/4); delay(200); digitalWrite(meter4, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/5); delay(200); digitalWrite(meter5, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/6); delay(200); digitalWrite(meter6, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/7); delay(200); digitalWrite(meter7, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/8); delay(200); digitalWrite(meter8, HIGH); digitalWrite(coldFish, LOW); needle.write((needlePosition+120)/9); delay(200); digitalWrite(meter9, HIGH); while(true) { digitalWrite(hotStuff, HIGH); digitalWrite(4, LOW); needle.write(needlePosition); delay(200); digitalWrite(hotStuff, LOW); digitalWrite(4, HIGH); delay(200); } } }