This post may contain an affiliate link that helps support GBFans.com when you make a purchase at no additional cost to you.I might as well share the code for all of this. I don't have any full diagrams of everything but it's not that complex. I have zipped everything up including my Eagle board/schematic files if you wanted to order from oshpark or modify my boards. I have some extra 5v outputs on the rail and an extra LED spot. It also has an extra separate input with a capacitor. I was originally going to run the servo off the 5v from arduino but decided things would be more stable to run from the buck converter and the boards were already in fab when I decided to do that.
It's been a fun project. Now I'm starting in on the pack using a pair of arduino nano's and an Adafruit Audio FX Sound Board
A zip file with the 3D model STL files for printing, eagle files for the pcb, and the arduino code The original model comes from here
http://www.thingiverse.com/thing:700251 and is under the creative commons license
https://creativecommons.org/licenses/by-sa/3.0/ As far as hardware goes it uses:
The wiring is not so hard. From the battery pack 1 power/ground to the arduino vin/gnd pins and 1 power/ground to the buck converter. The converter is then adjusted for a 5v output and that goes to the power/ground of the servo. The full pin out from the arduino looks like this:
Code: Select allvin/gnd - to power
5v/gnd - to board from oshpark
A4 - SDA on LCD Display
A5 - SLC on LCD Display
D3 - Button 1 +
D4 - Button 2 +
D5 - Buzzer +
D6 - LED 1 (A7 on OshPark board)
D7 - LED 2 (A6 on OshPark board)
D8 - LED 3 (A5 on OshPark board)
D9 - LED 4 (A4 on OshPark board)
D10 - LED 5 (A3 on OshPark board)
D11 - LED 6 (A2 on OshPark board)
D12 - LED 7 (A1 on OshPark board)
D13 - Servo Signal
OshPark Board
P1 - 5v + on LCD Display
G - Gnd on LCD Display
G - Gnd on Buzzer
G - Shared ground on button board
G - Shared ground on LED wings
For the LED's I used 1 output from 1-7 on the board from OshPark to each wing.
Yes I am using one resistor for 2 LED's.
The current in this setup is less than 10ma so they will be fine
And here is the arduino code.
Code: Select all#include <Servo.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
Servo SERVO1;
int LEDNum = 0; // current LED that is lit
unsigned long previousMillis; // will store last time LED was updated
const int LED1 = 12;
const int LED2 = 11;
const int LED3 = 10;
const int LED4 = 9;
const int LED5 = 8;
const int LED6 = 7;
const int LED7 = 6;
const int BUZZER = 5;
const int BUTTON1 = 3;
const int BUTTON2 = 4;
void setup() {
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
pinMode(LED6, OUTPUT);
pinMode(LED7, OUTPUT);
pinMode(BUZZER, OUTPUT);
pinMode(BUTTON1, INPUT);
pinMode(BUTTON2, INPUT);
digitalWrite(BUTTON1, HIGH);
digitalWrite(BUTTON2, HIGH);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.display();
delay(1000);
// Clear the buffer.
display.clearDisplay();
SERVO1.attach(13);
SERVO1.write(90);
}
void loop() {
int convertedVal = 0;
if (digitalRead(BUTTON1) == false) {
convertedVal = 40;
}else if(digitalRead(BUTTON2) == false) {
convertedVal = 90;
}
// do the led stuff
LEDLoop(convertedVal);
// do the servo stuff
ServoLoop(convertedVal);
// delay in between reads for stability
delay(1);
}
int prevB = 0;
void drawDisplay(int level, int bar) {
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(29, 5);
display.print("GHOSTBUSTERS");
int b1 = random(prevB, bar);
int b2 = random(prevB, bar);
int b3 = random(prevB, bar);
int b4 = random(prevB, bar);
int b5 = random(prevB/2, bar/2);
int b6 = random(prevB/2, bar/2);
prevB = bar;
display.fillRect(2, display.height() - (5 + b1), 5, b1, WHITE);
display.fillRect(10, display.height() - (5 + b2), 5, b2, WHITE);
display.fillRect(18, display.height() - (5 + b5), 5, b5, WHITE);
display.fillRect(display.width() - 23, display.height() - (5 + b6), 5, b6, WHITE);
display.fillRect(display.width() - 15, display.height() - (5 + b4), 5, b4, WHITE);
display.fillRect(display.width() - 7, display.height() - (5 + b3), 5, b3, WHITE);
display.drawCircle(display.width() / 2, display.height() / 2 + 7, level, WHITE);
display.display();
}
void clearLoop() {
display.clearDisplay();
prevB = 0;
}
void LEDLoop(int convertedVal) {
int ledSpeed = map(convertedVal, 0, 100, 500, 20);
// check to see if it's time to change the state of the LED
unsigned long currentMillis = millis();
if ((currentMillis - previousMillis >= ledSpeed))
{
previousMillis = millis();
if ( LEDNum == 0 ) {
TriggerBuzzer();
clearLoop();
digitalWrite(LED3, true);
LEDNum = 1;
drawDisplay(21, 5);
} else if ( LEDNum == 1 ) {
TriggerBuzzer();
digitalWrite(LED3, false);
digitalWrite(LED1, true);
LEDNum = 2;
drawDisplay(18, 20);
} else if ( LEDNum == 2 ) {
TriggerBuzzer();
digitalWrite(LED1, false);
digitalWrite(LED6, true);
LEDNum = 3;
drawDisplay(15, 30);
} else if ( LEDNum == 3 ) {
TriggerBuzzer();
digitalWrite(LED6, false);
digitalWrite(LED4, true);
LEDNum = 4;
drawDisplay(12, 45);
} else if ( LEDNum == 4 ) {
TriggerBuzzer();
digitalWrite(LED4, false);
digitalWrite(LED7, true);
LEDNum = 5;
drawDisplay(9, 50);
} else if ( LEDNum == 5 ) {
TriggerBuzzer();
digitalWrite(LED7, false);
digitalWrite(LED5, true);
LEDNum = 6;
drawDisplay(6, 55);
} else if ( LEDNum == 6 ) {
TriggerBuzzer();
digitalWrite(LED5, false);
digitalWrite(LED2, true);
LEDNum = 7;
drawDisplay(3, 65);
}else if ( LEDNum == 7 ) {
TriggerBuzzer();
clearLoop();
digitalWrite(LED2, false);
digitalWrite(LED3, true);
LEDNum = 1;
drawDisplay(21, 5);
}
}
}
void TriggerBuzzer() {
tone(BUZZER, 2000); // Send 2KHz sound signal...
delay(20); // ...for 20 msec
noTone(BUZZER);
}
void ServoLoop(int convertedVal) {
int servoVal = map(convertedVal, 0, 100, 110, 40);
SERVO1.write(servoVal);
}