Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define BLUE 11
- #define RED 10
- #define GREEN 9
- #define BUTTON 7
- #define OFFSET 2.0943951023931953 // 2/3 PI
- int val = 0;
- int state = 1;
- int pressed = 0;
- void setup() {
- pinMode(BLUE, OUTPUT);
- pinMode(RED, OUTPUT);
- pinMode(GREEN, OUTPUT);
- pinMode(BUTTON, INPUT);
- }
- void loop() {
- if (digitalRead(BUTTON)) {
- if (!pressed) {
- state = 1 - state;
- pressed = 1;
- delay(10);
- }
- } else {
- if (pressed) {
- pressed = 0;
- delay(10);
- }
- }
- delay(1);
- if (state) {
- double t = millis() / 5000.0;
- analogWrite(RED, (sin(t) + 1) * 30);
- t -= OFFSET;
- analogWrite(GREEN, (sin(t) + 1) * 30);
- t -= OFFSET;
- analogWrite(BLUE, (sin(t) + 1) * 8); // Blue is bad for sleep, so tone it down.
- } else {
- analogWrite(RED, 0);
- analogWrite(GREEN, 0);
- analogWrite(BLUE, 0);
- }
- }
Add Comment
Please, Sign In to add comment