Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // sensorValue = analogRead(sensorPin);
- // Input pins
- int potmeterPin = A0;
- int presetPin = 2;
- int huePin = 3;
- // -
- int potmeterValue = 0;
- int presetPressed = 0;
- int huePressed = 0;
- // Output pins
- int redPin = 9;
- int greenPin = 10;
- int bluePin = 11;
- // -
- int redValue = 255;
- int greenValue = 0;
- int blueValue = 0;
- // Others vars
- boolean demo = true;
- int msdelay = 5; // Delay between changing colors
- //-//-//-//-//-//
- void demoMode() {
- while (blueValue < 255 && demo)
- {
- demoColorChange(bluePin, 1, "blue");
- }
- while (redValue > 0 && demo)
- {
- demoColorChange(redPin, -1, "red");
- }
- while (greenValue < 255 && demo)
- {
- demoColorChange(greenPin, 1, "green");
- }
- while (blueValue > 0 && demo)
- {
- demoColorChange(bluePin, -1, "blue");
- }
- while (redValue < 255 && demo)
- {
- demoColorChange(redPin, 1, "red");
- }
- while (greenValue > 0 && demo)
- {
- demoColorChange(greenPin, -1, "green");
- }
- }
- void demoColorChange(int pin, int plusmin, char color) {
- if (digitalRead(presetPin) == 0 && digitalRead(huePin) == 0) {
- if (color == "red")
- {
- analogWrite(pin, redValue);
- redValue += plusmin;
- }
- if (color == "green")
- {
- analogWrite(pin, greenValue);
- greenValue += plusmin;
- }
- if (color == "blue")
- {
- analogWrite(pin, blueValue);
- blueValue += plusmin;
- }
- delay(msdelay);
- }
- else
- {
- endDemo();
- }
- }
- void endDemo() {
- demo = false;
- }
- void setup() {
- pinMode(potmeterPin, INPUT);
- pinMode(presetPin, INPUT);
- pinMode(huePin, INPUT);
- pinMode(redPin, OUTPUT);
- pinMode(greenPin, OUTPUT);
- pinMode(bluePin, OUTPUT);
- }
- void loop() {
- if (demo)
- demoMode();
- else
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement