Created
October 2, 2016 16:25
-
-
Save hhayley/552a759cb1ef8ed9acf89d737d6f2315 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 = 3; | |
int switchValue = 0; | |
int poten = A0; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(transistorPin, OUTPUT); | |
pinMode(redSwitch, INPUT); | |
pinMode(poten, INPUT); | |
} | |
void loop() { | |
switchValue = digitalRead(redSwitch); | |
if (switchValue == 1) { | |
int sensorValue = analogRead(A0); | |
// map the sensor value to a range from 0 - 255: | |
int outputValue = map(sensorValue, 0, 1023, 0, 255); | |
analogWrite(transistorPin, outputValue); | |
} else { | |
analogWrite(transistorPin, 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment