Created
October 5, 2016 06:04
-
-
Save hhayley/ce661bfe67cf38563bab01cbfb6ab839 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
const int transistorPin = 9; | |
int redSwitch = 8; | |
int switchValue = 0; | |
int poten = A0; | |
int B = 3; //Connect Blue led to Digital pin 3 | |
int R = 5; //Connect Red led to Digital pin 5 | |
int G = 6; //Connect Green led to Digital pin 6 | |
int val; | |
int potpin = A1; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(transistorPin, OUTPUT); | |
delay(1); | |
pinMode(redSwitch,INPUT); | |
pinMode(poten, INPUT); | |
pinMode(3,OUTPUT); | |
pinMode(5,OUTPUT); | |
pinMode(6,OUTPUT); | |
} | |
void loop() { | |
switchValue = digitalRead(redSwitch); | |
//Serial.println(switchValue); | |
if(switchValue == 1){ | |
// read the potentiometer: | |
int sensorValue = analogRead(A0); | |
// map the sensor value to a range from 0 - 255: | |
int outputValue = map(sensorValue, 0, 1023, 0, 255); | |
// use that to control the transistor: | |
analogWrite(transistorPin, outputValue); | |
val = analogRead(potpin); | |
val = map(val,0,1023,1,1000); | |
analogWrite(B,255); | |
analogWrite(R,255); | |
analogWrite(G,255); | |
delay(val); | |
analogWrite(B,0); | |
analogWrite(R,0); | |
analogWrite(G,0); | |
delay(val); | |
}else{ | |
analogWrite(transistorPin, 0); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment