Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 859aff9dd7547c27407d061a5aaf23b784a0c641 Erica committed Apr 9, 2011
Showing with 107 additions and 0 deletions.
  1. 0 README
  2. +107 −0 Train-Overlord.pde
0 README
No changes.
@@ -0,0 +1,107 @@
+#define RED 1100
+#define GREEN 1010
+#define BLUE 1001
+#define YELLOW 1110
+#define PURPLE 1101
+#define TEAL 1011
+#define WHITE 1111
+
+#define BACKMULTI 1.0
+#define FWDMULTI 1.1
+
+class LED
+{
+ public:
+ LED(int,int,int);
+ void setColor(int);
+
+ int PinGreen;
+ int PinBlue;
+ int PinRed;
+};
+
+LED::LED (int pinG, int pinB, int pinR) {
+ PinGreen = pinG;
+ PinBlue = pinB;
+ PinRed = pinR;
+}
+
+void LED::setColor(int color) {
+ switch(color) {
+ case RED:
+ digitalWrite(PinRed, LOW);
+ digitalWrite(PinGreen, HIGH);
+ digitalWrite(PinBlue, HIGH);
+ break;
+ case YELLOW:
+ digitalWrite(PinRed, LOW);
+ digitalWrite(PinGreen, LOW);
+ digitalWrite(PinBlue, HIGH);
+ break;
+ case PURPLE:
+ digitalWrite(PinRed,LOW);
+ digitalWrite(PinGreen, HIGH);
+ digitalWrite(PinBlue, LOW);
+ break;
+ case WHITE:
+ digitalWrite(PinRed, LOW);
+ digitalWrite(PinGreen, LOW);
+ digitalWrite(PinBlue, LOW);
+ break;
+ case TEAL:
+ digitalWrite(PinRed, HIGH);
+ digitalWrite(PinGreen, LOW);
+ digitalWrite(PinBlue, LOW);
+ break;
+ case GREEN:
+ digitalWrite(PinRed, HIGH);
+ digitalWrite(PinGreen, LOW);
+ digitalWrite(PinBlue, HIGH);
+ break;
+ case BLUE:
+ digitalWrite(PinRed, HIGH);
+ digitalWrite(PinGreen, HIGH);
+ digitalWrite(PinBlue, LOW);
+ break;
+ }
+}
+
+#include <AFMotor.h>
+
+LED myLED(6,5,3);
+AF_DCMotor motor1(1, MOTOR12_8KHZ); //create motor #1, 64KHz pwm
+
+void setup()
+{
+ motor1.setSpeed(200); //set the speed to 200/255
+ motor1.run(RELEASE);
+ pinMode(myLED.PinRed, OUTPUT);
+ pinMode(myLED.PinBlue, OUTPUT);
+ pinMode(myLED.PinGreen, OUTPUT);
+
+ digitalWrite(myLED.PinRed, HIGH);
+ digitalWrite(myLED.PinBlue, HIGH);
+ digitalWrite(myLED.PinGreen, HIGH);
+}
+
+
+void loop()
+{
+ myLED.setColor(GREEN);
+ motor1.run(FORWARD);
+ motor1.setSpeed(255);
+ delay(16000);
+ motor1.run(RELEASE);
+ myLED.setColor(BLUE);
+ delay(500);
+ myLED.setColor(RED);
+ motor1.run(BACKWARD);
+ motor1.setSpeed(255);
+ delay(16000);
+ motor1.run(RELEASE);
+ myLED.setColor(TEAL);
+ delay(500);
+}
+
+
+

0 comments on commit 859aff9

Please sign in to comment.