Advertisement
3rdWard_Arduino

class4_GSR PWM pin 11

Feb 15th, 2012
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int sensorPin = A0;    // select the input pin for the wires for Galvanic Skin Response
  2. int ledPin = 11;      // select the pin for the LED
  3. int sensorValue = 0;  // variable to store the value coming from the sensor
  4. int lowestVal = 1023;
  5. int highestVal = 0;
  6. int pwmVal = 0;
  7.  
  8. void setup() {
  9.   // declare the ledPin as an OUTPUT:
  10.   pinMode(ledPin, OUTPUT);  
  11.   Serial.begin(9600);
  12.   pinMode(13, OUTPUT);
  13.   digitalWrite(13, HIGH);
  14.   for(int i = 0; i < 6000; i++){
  15.     // read the current value from the GSR
  16.     sensorValue = analogRead(sensorPin);
  17.     //check to see if the value is greater than highestVal ...
  18.     if( sensorValue > highestVal){
  19.      highestVal = sensorValue;
  20.     }
  21.     // or less than lowestVal
  22.     if( sensorValue < lowestVal){
  23.      lowestVal = sensorValue;
  24.     }
  25.     delay(1);
  26.   }
  27.   digitalWrite(13, LOW);
  28. }
  29.  
  30. void loop() {
  31.   // read the value from the sensor:
  32.   sensorValue = analogRead(sensorPin);
  33.   Serial.println( sensorValue );
  34.   sensorValue = constrain(sensorValue, lowestVal, highestVal);
  35.   pwmVal = map( sensorValue, lowestVal, highestVal, 0, 255);
  36.   analogWrite(ledPin, pwmVal);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement