Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1.  
  2. int fsrAnalogPin = 0; // FSR is connected to analog 0
  3. int LEDpin = 11; // connect LED to pin 11 (PWM pin)
  4. int fsrReading; // the analog reading from the FSR resistor divider
  5. int LEDbrightness;
  6.  
  7. void setup(void) {
  8. Serial.begin(9600); // send debugging information via the Serial monitor
  9. pinMode(LEDpin, OUTPUT);
  10. }
  11.  
  12. void loop(void) {
  13. fsrReading = analogRead(fsrAnalogPin);
  14. Serial.print("Analog reading = ");
  15. Serial.println(fsrReading);
  16.  
  17. // we'll need to change the range from the analog reading (0-1023) down to the range
  18. // used by analogWrite (0-255) with map!
  19. LEDbrightness = map(fsrReading, 0, 1023, 0, 255);
  20. // LED gets brighter the harder you press
  21. analogWrite(LEDpin, LEDbrightness);
  22. delay(100);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement