Skip to content

Instantly share code, notes, and snippets.

@natendaben
Created October 4, 2018 14:43
Show Gist options
  • Save natendaben/5de4e91eac48b3aa19a787100390429a to your computer and use it in GitHub Desktop.
Save natendaben/5de4e91eac48b3aa19a787100390429a to your computer and use it in GitHub Desktop.
Lab2pt1
//analog inout and output
int pot = 0; //stores pot value
int potPin = A0;
int redLED = 9;
int brightness1 = 0; //value to hold LED brightness
int brightness2 = 0;
int photoPin = A1;
int lightValue = 0;
int yellowLED = 10;
void setup() {
// put your setup code here, to run once:
//setup serial comm
Serial.begin(9600); //set up serial comm
pinMode(redLED, OUTPUT); //LED output
pinMode(yellowLED, OUTPUT);
}
void loop() {
// read pot
pot = analogRead(potPin);
lightValue = analogRead(photoPin);
//Serial.print("Pot value: "); //prints without line break
//Serial.println(pot); //prints with line break
//use map() to convert 0-1023 to 0-255
//map(valueToMap, fromLow, fromHigh, toLow, toHigh);
brightness1 = map(pot, 0, 1023, 0, 255);
analogWrite(9, brightness1);
brightness2 = map(lightValue, 0, 1023, 0, 255);
analogWrite(10, brightness2);
Serial.print("Pressure val: ");
Serial.println(brightness2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment