Created
June 24, 2014 05:28
-
-
Save makenai/a5a49096333a7baaac33 to your computer and use it in GitHub Desktop.
SumoBot Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Scout.h> | |
#include <SPI.h> | |
#include <Wire.h> | |
#include <Scout.h> | |
#include <GS.h> | |
#include <bitlash.h> | |
#include <lwm.h> | |
#include <js0n.h> | |
#include <NESpad.h> | |
#define HALT 0 | |
#define FORWARD 2 | |
#define BACKWARD 1 | |
#define LEFT 3 | |
#define RIGHT 4 | |
NESpad nintendo = NESpad(3,4,5,6); | |
byte state1 = 0; | |
byte state2 = 0; | |
int lastMessages[12]; | |
void setup() { | |
Scout.setup("SoccerBots"); | |
Scout.setMode(3, OUTPUT); | |
Scout.setMode(4, OUTPUT); | |
Scout.setMode(5, INPUT); | |
Scout.setMode(6, INPUT); | |
} | |
void tellScout( int scoutId, int command ) { | |
char buffer[128]; | |
if ( lastMessages[ scoutId ] != command ) { | |
sprintf( buffer, "message.scout(%d,\"%d\");", scoutId, command ); | |
doCommand( buffer ); | |
Serial.println( buffer ); | |
lastMessages[ scoutId ] = command; | |
} | |
} | |
void handleState( byte state, int scoutId ) { | |
if ( state & NES_A ) | |
tellScout( scoutId, HALT ); | |
if ( state & NES_B ) | |
tellScout( scoutId, HALT ); | |
if ( state & NES_UP ) | |
tellScout( scoutId, FORWARD ); | |
if ( state & NES_DOWN ) | |
tellScout( scoutId, BACKWARD ); | |
if ( state & NES_LEFT ) | |
tellScout( scoutId, LEFT ); | |
if ( state & NES_RIGHT ) | |
tellScout( scoutId, RIGHT ); | |
} | |
void loop() { | |
nintendo.buttons(); | |
state1 = nintendo.buttons1; | |
state2 = nintendo.buttons2; | |
handleState( state1, 2 ); | |
handleState( state2, 6 ); | |
Scout.loop(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function startup { timer3.initialize(20000); s = 89; }; | |
function forward { timer3.pwm(3,180); timer3.pwm(4,1); }; | |
function halt { timer3.pwm(3,90); timer3.pwm(4,90); }; | |
function backward { timer3.pwm(3,1); timer3.pwm(4,180); }; | |
function right { timer3.pwm(3,180); timer3.pwm(4,180); }; | |
function left { timer3.pwm(3,1); timer3.pwm(4,1); }; | |
function on.message.scout { | |
print arg(2); | |
if ( key.number( arg(2) ) == 0 ) halt(); | |
if ( key.number( arg(2) ) == 3 ) left(); | |
if ( key.number( arg(2) ) == 4 ) right(); | |
if ( key.number( arg(2) ) == 2 ) forward(); | |
if ( key.number( arg(2) ) == 1 ) backward(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment