SHOW:
|
|
- or go back to the newest paste.
1 | - | int sensorPin = A0; // select the input pin for the potentiometer |
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 | - | |
7 | + | |
8 | void setup() { | |
9 | // declare the ledPin as an OUTPUT: | |
10 | pinMode(ledPin, OUTPUT); | |
11 | Serial.begin(9600); | |
12 | - | for(int i = 0; i < 3000; i++){ |
12 | + | pinMode(13, OUTPUT); |
13 | - | // read the current value from the photocell |
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 | - | highestVal = sensorValue; |
17 | + | |
18 | if( sensorValue > highestVal){ | |
19 | highestVal = sensorValue; | |
20 | } | |
21 | - | lowestVal = sensorValue; |
21 | + | |
22 | if( sensorValue < lowestVal){ | |
23 | - | delay(1); |
23 | + | lowestVal = sensorValue; |
24 | } | |
25 | delay(1); | |
26 | - | |
26 | + | |
27 | digitalWrite(13, LOW); | |
28 | } | |
29 | - | sensorValue = analogRead(sensorPin); |
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 | } |