I am entering in 3 all three categories. Best Presentation, Best Result and Most Overkill.
Here is my submission video for the Santa Pede competition. I'm hoping I get best presentation.
CLICK LINK FOR VIDEO
http://www.youtube.com/watch?v=J77CKDWHwD0
Here is the code for the Arduino used in the most overkill
- Code: Select all
int WALK=46;
int EYES=43;
int SPEAKER=3;
int GUNLED=53;
int ROCKETLED=2;
String Login="Santa";
String Password="Ho";
String Message="";
boolean MessageWasReceived=false;
boolean DisplaySerial=false;
boolean DisplayReceivedMessage=false;
boolean Hardcore=false;
int SoundTimer=0;
int SoundTone=50;
///if (SoundTimer != 0){ SoundTimer=millis()+100;}
//if (SoundTimer = millis() ) {
// }
void setup() {
pinMode(WALK, OUTPUT);
pinMode(EYES, OUTPUT);
pinMode(SPEAKER, OUTPUT);
pinMode(GUNLED, OUTPUT);
pinMode(ROCKETLED,OUTPUT);
tone(SPEAKER, 1000, 100);
delay(500);
//rampageMode();
Serial.begin(9600);
login();
Serial.println("\n");
Serial.println("Welcome to Santa OS Mother Fucker");
systemStatus();
}
void loop() {
receiveSerial();
if ( MessageWasReceived){
doStuff();
}
}
void rampageMode(){
int RampageWalkTimer=0;
boolean Walking=true;
RampageWalkTimer=millis()+1000;
doWalk();
int Action=0;
ack();
while ( 1 == 1 ) {
receiveSerial();
if ( Message != "" ){
if ( Walking == true ){
Walking=false;
doWalk();
}
ack();
return;
}
if ( Action == 0 ) {
targetingSound();
rocketSound();
}
if ( Action == 1 ) {
targetingSound();
rocketSound();
}
if ( ( Walking == true ) && ( millis() > RampageWalkTimer ) ){
doWalk();
RampageWalkTimer=0;
Walking=false;
}
if ( ( Walking == false ) && ( Action == 2 ) ) {
RampageWalkTimer=millis()+1000;
Walking=true;
doWalk();
}
if ( Action == 3 ){
rocketSound();
}
if ( Action == 4 ){
rocketSound();
}
if (Action >= 5 ){
gunSound();
}
Action=random(10);
}
}
void badSound(){
tone(SPEAKER, 60, 100);
delay(200);
tone(SPEAKER, 60, 500);
delay(1000);
}
void targetingSound(){
int freq=1500;
for (int i=0; i < 2; i++){
digitalWrite(EYES,HIGH);
tone(SPEAKER, freq);
delay(200);
digitalWrite(EYES,LOW);
noTone(SPEAKER);
delay(200);
}
int i=80;
while (i>10){
digitalWrite(EYES,HIGH);
tone(SPEAKER, freq);
delay(i);
digitalWrite(EYES,LOW);
noTone(SPEAKER);
delay(i);
i=i-10;
}
i=0;
while (i<15){
digitalWrite(EYES,HIGH);
tone(SPEAKER, freq);
delay(20);
digitalWrite(EYES,LOW);
noTone(SPEAKER);
delay(20);
i++;
}
//tone(SPEAKER, 1000);
//delay(500);
noTone(SPEAKER);
digitalWrite(EYES,HIGH);
}
void rocketSound(){
for (int y=5; y>1; y-- ){
for (int x=0; x<=10; x++){
int dly=random(y);
digitalWrite(ROCKETLED,HIGH);
digitalWrite(SPEAKER,HIGH);
delay(dly);
dly=random(y);
digitalWrite(ROCKETLED,LOW);
digitalWrite(SPEAKER,LOW);
delay(dly);
}
}
for (int y=1; y<20; y++ ){
if ( y >= 6 ) {y++;}
for (int x=0; x<=10; x++){
int dly=random(y);
digitalWrite(ROCKETLED,HIGH);
digitalWrite(SPEAKER,HIGH);
delay(dly);
dly=random(y);
digitalWrite(ROCKETLED,LOW);
digitalWrite(SPEAKER,LOW);
delay(dly);
}
}
digitalWrite(EYES,HIGH);
}
void gunSound() {
for (int x=0; x <= 3; x++) {
digitalWrite(GUNLED, HIGH);
for (int dly=0; dly <= 11; dly++){
digitalWrite(SPEAKER,HIGH);
delay(dly);
dly++;
digitalWrite(SPEAKER,LOW);
delay(dly);
}
delay(30);
digitalWrite(GUNLED,LOW);
delay(70);
}
}
void startSound() {
int FreqSound=40;
int timer=100;
for ( int Counter = 0; Counter <= 30; Counter++ ) {
tone(SPEAKER,FreqSound);
FreqSound=FreqSound+300;
delay(5);
}
digitalWrite(WALK,HIGH);
delay(10);
digitalWrite(WALK,LOW);
delay(300);
digitalWrite(WALK,HIGH);
delay(10);
noTone(SPEAKER);
digitalWrite(WALK,LOW);
}
void systemStatus() {
Serial.println("Status: Online");
Serial.print("System runtime: ");
long time=millis()/1000;
Serial.print( time );
Serial.println( "Seconds \n" );
Serial.print(">");
}
void ack(){
Message="";
MessageWasReceived=false;
}
void login (){
digitalWrite(EYES, LOW);
boolean Authenticated=false;
boolean LoginVerified=false;
while ( Message == "" ) { receiveSerial(); }
ack();
DisplaySerial=true;
while ( ! Authenticated ) {
Serial.println("sOS 1.0");
Serial.print("Login:");
while ( ! LoginVerified ) {
receiveSerial();
if ( ( MessageWasReceived ) && ( Message == Login ) ) {
ack();
LoginVerified=true;
} else if( ( MessageWasReceived ) && ( Message != Login ) ) {
LoginVerified=false;
Serial.println("\nInvalid Username");
badSound();
ack();
break;
}
}
if ( LoginVerified ) {
Serial.print("\nPassword:");
}
while ( LoginVerified ) {
receiveSerial();
if ( ( MessageWasReceived ) && ( Message == Password ) ){
ack();
startSound();
Authenticated=true;
LoginVerified=false;
digitalWrite(EYES, HIGH);
} else if ( ( MessageWasReceived ) && ( Message != Password ) ) {
ack();
LoginVerified=false;
Serial.println("\nInvalid Password.");
badSound();
}
}
}
}
void receiveSerial (){
char CharacterReceived=0;
if ( Serial.available() > 0 ) {
CharacterReceived=Serial.read();
if ( DisplaySerial ){ Serial.print(CharacterReceived); }
if ( CharacterReceived == 13 ) {
if ( DisplayReceivedMessage ) {
Serial.print("Command Received: ");
Serial.println(Message);
}
MessageWasReceived=true;
} else {
Message= ( Message + CharacterReceived );
}
}
}
void doWalk(){
digitalWrite(WALK, HIGH);
delay(20);
digitalWrite(WALK, LOW);
}
void doStuff(){
int SwitchCommand=0;
if ( Message == "walk" ){ SwitchCommand=1;}
if ( Message == "stop" ){ SwitchCommand=2;}
if ( Message == "obj" ){ SwitchCommand=3;}
if ( Message == "shoot" ){ SwitchCommand=4;}
if ( Message == "hohoho" ){ SwitchCommand=5;}
if ( Message == "help" ){ SwitchCommand=6;}
if ( Message == "rocket" ){ SwitchCommand=7;}
if ( Message == "logoff" ){ SwitchCommand=8;}
if ( Message == "logout" ){ SwitchCommand=8;}
if ( Message == "rampage" ){ SwitchCommand=9;}
switch (SwitchCommand) {
case 1:
Serial.println("Walking..");
doWalk();
break;
case 2:
Serial.println("Stopping...");
doWalk();
break;
case 3:
if ( ! Hardcore ){
Serial.println("Prime Objectives: ");
Serial.println("1. Ho Ho Ho ");
Serial.println("2. Merry Christmas ");
Serial.println("3. Feed Rudolph");
} else {
Serial.println("Prime Objectives: ");
Serial.println("1.Enforce Niceness");
}
break;
case 4:
Serial.println("firing");
gunSound();
break;
case 5:
Serial.println("Ho Ho Ho, Merry Christmas");
break;
case 6:
Serial.println("displaying help");
doHelp();
break;
case 7:
Serial.println("");
targetingSound();
rocketSound();
break;
case 8:
Serial.println("logging off");
setup();
break;
case 9:
Serial.println("rampage... press any key to stop");
rampageMode();
break;
default:
Serial.println("Unrecognized command");
break;
}
ack;
MessageWasReceived=false;
Message="";
Serial.print(">");
}
void doHelp(){
Serial.println("Commands:");
Serial.println("help - displays a helpful message");
Serial.println("walk - tells Santa to walk");
Serial.println("shoot - shoot guns");
Serial.println("rocket - fires rockets");
Serial.println("stop - stops all actions");
Serial.println("obj - show objectives");
Serial.println("rampage - go into hardcore mode");
}
/*
Commented out method of returning what was written
int NumberToReceive=Serial.available();
char ReceiveString[255]="";
int CharPosition=0;
while (NumberToReceive != 0 ){
ReceiveString[CharPosition]=Serial.read();
CharPosition++;
NumberToReceive=Serial.available();
}
if ( CharPosition != 0 ){
Serial.print(ReceiveString);
NumberToReceive=Serial.available();
if ( NumberToReceive == 0 ){
delay(2);
NumberToReceive=Serial.available();
if ( NumberToReceive == 0 ){
Serial.println("");
}
}
}
}
*/
Here is the permissions script for the web interface
- Code: Select all
stty -F /dev/ttyUSB0 speed 9600 ignbrk -raw -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok echoctl -echoke time 5 min 1 line 0
gksudo chmod 777 /dev/ttyUSB0
cat /dev/ttyUSB0
read -n1 p "press any key to stop santa communications" arbitraryVariable
Here is the CGI login script
- Code: Select all
adam@adam-desktop:/usr/lib/cgi-bin$ cat ./cmd.sh
#!/bin/bash
echo "Content-type: text/html"
echo ""
device=`echo "$QUERY_STRING" | sed -n 's/^.*device=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"|sed "s/%2F/\//g"`
command=`echo "$QUERY_STRING" | sed -n 's/^.*command=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`
echo -en "$command\r" >"$device"
cat /var/www/index.html
echo "$command""ing command sent to $device"
Here is the main CGI script which handles receiving commands, sending them to Serial, then returning the user to the main UI.
- Code: Select all
#!/bin/sh
echo "Content-type: text/html"
echo ""
device=`echo "$QUERY_STRING" | sed -n 's/^.*device=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"|sed "s/%2F/\//g"`
echo -en "Santa\rHo\r" >$device
cat /var/www/index.html
here is the HTML which drives the web interface
- Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>SCP</title>
<meta name="generator" content="Bluefish 2.0.1" >
<meta name="author" content="adam" >
<meta name="date" content="2011-01-15T09:39:02-0600" >
<meta name="copyright" content="">
<meta name="keywords" content="">
<meta name="description" content="Santa Clause Web Interface">
<meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="content-style-type" content="text/css">
<meta http-equiv="expires" content="0">
</head>
<body>
<p>
</p>
<h1 style="text-align: left;">Welcome to Santa Control</h1>
<div style="text-align: center;">
<div style="position: absolute; left: 182px; top: 94px;"><br>
</div>
<div
style="position: absolute; left: 91px; top: 77px; width: 92px; height: 50px;">
<form action="/cgi-bin/SantaLogin.cgi" method="get"> <input
name="device" value="/dev/ttyUSB0" type="hidden"> <input value="Login"
type="submit"> </form>
</div>
<object data="/santa.jpg" type="image/jpg"></object>
<div style="position: absolute; left: 11px; top: 163px; height: 106px;">
<form action="/cgi-bin/cmd.sh" method="get"> <input name="device"
value="/dev/ttyUSB0" type="hidden"> <input class="bginput"
value="walk" name="command" type="submit">
<input alt="56456356" value="stop" name="command"
type="submit"> <input
value="fire" name="command" type="submit"> <br>
<br>
<br>
<br>
<input value="logoff" name="command" type="submit"> <br>
<br>
<br>
<input class="bginput"
value="rampage" name="command" type="submit">
</form>
</div>
</div>
<pre><!--#include virtual="/cgi-bin/cgi.cgi" --></pre>
</body>
</html>
