SHARE
TWEET

exercise 3

Rywo Jun 18th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sefloat sensorValue = 0; // variable for sensor value
  2. float sensorPin = A0; // variable for sensor pin
  3. int greenLedPin = 10;
  4. int yellowLedPin = 9;
  5.  
  6. void setup() {
  7.  pinMode(sensorPin, INPUT);
  8.  Serial.begin(9600);
  9.  pinMode(greenLedPin, OUTPUT);
  10.  pinMode(yellowLedPin, OUTPUT);
  11. }
  12. void loop() {
  13.  sensorValue = analogRead(sensorPin);
  14.  sensorValue = (sensorValue/1023)*255;
  15.  Serial.println(sensorValue); // print out sensorValue to the Serial Monitor
  16.  delay(20); // delay for 0.2 seconds
  17.   analogWrite(greenLedPin, sensorValue);
  18.  analogWrite(yellowLedPin, sensorValue);
  19.  
  20.   int val = analogRead(0);
  21.  val = map(val, 0, 1023, 0, 255);
  22.  analogWrite(greenLedPin, val);
  23.  
  24.  int val2 = analogRead(0);
  25.  val2 = map(val2, 0, 1023, 255, 0);
  26.  analogWrite(yellowLedPin, val2);
  27. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top