Last active
November 30, 2017 15:08
-
-
Save YukinaMochizuki/863d31f28e0b9d0d815d8ffc1b0a82d7 to your computer and use it in GitHub Desktop.
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 <SoftwareSerial.h> | |
const byte ledCount = 2; | |
byte ledPins[] = {5, 6}; | |
byte led1 = 0; | |
byte led2 = 0; | |
byte nowled = 0; | |
void light11() { | |
if (led1 == 0) { | |
for (int fadeValue = 0 ; fadeValue <= 100; fadeValue += 5) { | |
analogWrite(ledPins[0], fadeValue); | |
delay(30); | |
led1 = 2; | |
} | |
} else if (led1 == 1) { | |
for (int fadeValue = 255 ; fadeValue >= 100; fadeValue -= 5) { | |
analogWrite(ledPins[0], fadeValue); | |
delay(30); | |
led1 = 2; | |
} | |
} | |
if (led2 == 0) { | |
for (int fadeValue = 0 ; fadeValue <= 100; fadeValue += 5) { | |
analogWrite(ledPins[1], fadeValue); | |
delay(30); | |
led2 = 2; | |
} | |
} else if (led2 == 1) { | |
for (int fadeValue = 255 ; fadeValue >= 100; fadeValue -= 5) { | |
analogWrite(ledPins[1], fadeValue); | |
delay(30); | |
led2 = 2; | |
} | |
} | |
} | |
void light(byte num1, byte num2) { | |
if (num1 == 1) { | |
if (led1 == 0) { | |
for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) { | |
analogWrite(ledPins[0], fadeValue); | |
delay(30); | |
led1 = 1; | |
} | |
}else if(led1 == 2){ | |
for (int fadeValue = 100 ; fadeValue <= 255; fadeValue += 5) { | |
analogWrite(ledPins[0], fadeValue); | |
delay(30); | |
led1 = 1; | |
} | |
} | |
} else if (num1 == 0) { | |
if (led1 == 1) { | |
for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) { | |
analogWrite(ledPins[0], fadeValue); | |
delay(30); | |
led1 = 0; | |
} | |
}else if(led1 == 2){ | |
for (int fadeValue = 100 ; fadeValue >= 0; fadeValue -= 5) { | |
analogWrite(ledPins[0], fadeValue); | |
delay(30); | |
led1 = 0; | |
} | |
} | |
} | |
if (num2 == 1) { | |
if (led2 == 0) { | |
for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) { | |
analogWrite(ledPins[1], fadeValue); | |
delay(30); | |
led2 = 1; | |
} | |
}else if(led2 == 2){ | |
for (int fadeValue = 100 ; fadeValue <= 255; fadeValue += 5) { | |
analogWrite(ledPins[1], fadeValue); | |
delay(30); | |
led2 = 1; | |
} | |
} | |
} else if (num2 == 0) { | |
if (led2 == 1) { | |
for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) { | |
analogWrite(ledPins[1], fadeValue); | |
delay(30); | |
led2 = 0; | |
} | |
}else if(led2 == 2){ | |
for (int fadeValue = 100 ; fadeValue >= 0; fadeValue -= 5) { | |
analogWrite(ledPins[1], fadeValue); | |
delay(30); | |
led2 = 0; | |
} | |
} | |
} | |
} | |
void slight(int num) { | |
if (num == 0) { | |
light11(); | |
} else if (num == 1) { | |
light(0, 1); | |
} else if (num == 2) { | |
light(1, 0); | |
} else if (num == 3) { | |
light(0, 0); | |
} | |
} | |
void intt(){ | |
nowled++; | |
if(nowled == 4)nowled = 0; | |
slight(nowled); | |
} | |
void setup() { | |
for (byte thisLed = 0; thisLed < ledCount; thisLed++) { | |
pinMode(ledPins[thisLed], OUTPUT); | |
} | |
Serial.begin(9600); | |
pinMode(2, INPUT); | |
} | |
void loop() { | |
int switchStatus = digitalRead(2); | |
digitalWrite(13, switchStatus); | |
Serial.println(switchStatus); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment