Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added analog capabilities

  • Loading branch information...
commit c3d6dfadd4bba57855ec6354b0cab53c73309083 1 parent bfb8357
@nyaculak authored
Showing with 83 additions and 75 deletions.
  1. +83 −75 LED.ino
View
158 LED.ino
@@ -36,97 +36,105 @@ public:
green->off();
blue->off();
}
- void showGreen();
- void showBlue();
- void showYellow();
- void showMagenta();
- void showCyan();
- void showWhite();
+ void showGreen() {
+ red->off();
+ green->on();
+ blue->off();
+ }
+ void showBlue() {
+ red->off();
+ green->off();
+ blue->on();
+ }
+ void showYellow() {
+ red->on();
+ green->on();
+ blue->off();
+ }
+ void showMagenta() {
+ red->on();
+ green->off();
+ blue->on();
+ }
+ void showCyan() {
+ red->off();
+ green->on();
+ blue->on();
+ }
+ void showWhite() {
+ red->on();
+ green->on();
+ blue->on();
+ }
+ void showNone() {
+ red->off();
+ green->off();
+ blue->off();
+ }
+ void loopColors() {
+ showRed();
+ delay(500);
+ showYellow();
+ delay(500);
+ showGreen();
+ delay(500);
+ showBlue();
+ delay(500);
+ showMagenta();
+ delay(500);
+ showCyan();
+ delay(500);
+ showWhite();
+ delay(500);
+ }
private:
LED* red;
LED* green;
LED* blue;
-};/*
-void rgbLED::showRed() {
- red.on();
- green.off();
- blue.off();
-}*/
-// todo: make all of the following functions part
-// of the rgbLED class!
-
-// this one is mostly done
+};
LED red(13);
LED green(12);
LED blue(11);
-rgbLED triled(red&, green&, blue&);
-
-void showRed() {
- red->on();
- green->off();
- blue->off();
-}/*
-void showGreen() {
- red.off();
- green.on();
- blue.off();
-}
-void showBlue() {
- red.off();
- green.off();
- blue.on();
-}
-void showYellow() {
- red.on();
- green.on();
- blue.off();
-}
-void showMagenta() {
- red.on();
- green.off();
- blue.on();
-}
-void showCyan() {
- red.off();
- green.on();
- blue.on();
-}
-void showWhite() {
- red.on();
- green.on();
- blue.on();
-}
-void showNone() {
- red.off();
- green.off();
- blue.off();
-}
-void loopColors() {
- showRed();
- delay(500);
- showYellow();
- delay(500);
- showGreen();
- delay(500);
- showBlue();
- delay(500);
- showMagenta();
- delay(500);
- showCyan();
- delay(500);
- showWhite();
- delay(500);
-}*/
+rgbLED triled(&red, &green, &blue);
+
+int buttonPin = 0;
void setup() {
Serial.begin(9600);
Serial.println("Launching Program");
+ pinMode(buttonPin, INPUT);
}
+int loopCount;
+int val;
+int analogIn = A0;
+int buttonVal;
+
void loop() {
- showRed();
+ buttonVal = digitalRead(buttonPin);
+ val = analogRead(analogIn);
+
+ if (buttonVal == LOW) {
+
+ if (loopCount > 6) loopCount = 0;
+
+ if (loopCount == 0) triled.showRed();
+ if (loopCount == 1) triled.showYellow();
+ if (loopCount == 2) triled.showGreen();
+ if (loopCount == 3) triled.showBlue();
+ if (loopCount == 4) triled.showMagenta();
+ if (loopCount == 5) triled.showCyan();
+ if (loopCount == 6) triled.showWhite();
+ delay(val);
+
+ triled.showNone();
+ delay(val);
+
+ ++loopCount;
+ }
}
+
Please sign in to comment.
Something went wrong with that request. Please try again.