Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. //Analog Input and Output
  2.  
  3. int prePin = A0; //Analog input pin
  4. int potPin = A1; //Analog input pin
  5.  
  6. int pre = 0; //Stores Potentiometer 1 value
  7. int pot = 0; //Stores Potentiometer 2 value
  8.  
  9. int whiteLED1 = 10; //LED pin
  10. int whiteLED2 = 9; //LED pin
  11.  
  12. int brightness1 = 0; //value to hold LED brightness
  13. int brightness2 = 0;
  14.  
  15.  
  16. void setup()
  17. {
  18. // put your setup code here, to run once:
  19. Serial.begin(9600); //Setup serial communication
  20. pinMode(whiteLED1, OUTPUT); //LED output
  21. pinMode(whiteLED2, OUTPUT);
  22. }
  23.  
  24. void loop()
  25. {
  26. pre = analogRead(prePin);
  27. pot = analogRead(potPin);
  28.  
  29. //use map() to convert 0-1023 to 0-255 (Analog Input to Analog Output)
  30. //map(valueToMap, fromLow, fromHigh, toLow, toHigh);
  31.  
  32. brightness1 = map(pre, 0, 1023, 0, 255);
  33. analogWrite(10, brightness1);
  34.  
  35. brightness2 = map(pot, 0, 1023, 0, 255);
  36. analogWrite(9, brightness2);
  37.  
  38. Serial.print("Pre val: ");
  39. Serial.print(brightness1);
  40. Serial.print(", Pot val: ");
  41. Serial.println(brightness2);
  42. delay(200);
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement