SHARE
TWEET

Analog Input Sketch for ATtiny84

epl70 Feb 12th, 2016 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.   Analog Input
  3.  Demonstrates analog input by reading an analog sensor on analog pin 0 and
  4.  turning on and off a light emitting diode(LED)  connected to digital pin 13.
  5.  The amount of time the LED will be on and off depends on
  6.  the value obtained by analogRead().
  7.  
  8.  The circuit:
  9.  * Potentiometer attached to analog input 0
  10.  * center pin of the potentiometer to the analog pin
  11.  * one side pin (either one) to ground
  12.  * the other side pin to +5V
  13.  * LED anode (long leg) attached to digital output 13
  14.  * LED cathode (short leg) attached to ground
  15.  
  16.  * Note: because most Arduinos have a built-in LED attached
  17.  to pin 13 on the board, the LED is optional.
  18.  
  19.  
  20.  Created by David Cuartielles
  21.  modified 30 Aug 2011
  22.  By Tom Igoe
  23.  
  24.  This example code is in the public domain.
  25.  
  26.  http://www.arduino.cc/en/Tutorial/AnalogInput
  27.  
  28.  */
  29.  
  30. int sensorPin = A1;    // select the input pin for the potentiometer
  31. int ledPin = 0;      // select the pin for the LED
  32. int sensorValue = 0;  // variable to store the value coming from the sensor
  33.  
  34. void setup() {
  35.   // declare the ledPin as an OUTPUT:
  36.   pinMode(ledPin, OUTPUT);
  37. }
  38.  
  39. void loop() {
  40.   // read the value from the sensor:
  41.   sensorValue = analogRead(sensorPin);
  42.   // turn the ledPin on
  43.   digitalWrite(ledPin, HIGH);
  44.   // stop the program for <sensorValue> milliseconds:
  45.   delay(sensorValue);
  46.   // turn the ledPin off:
  47.   digitalWrite(ledPin, LOW);
  48.   // stop the program for for <sensorValue> milliseconds:
  49.   delay(sensorValue);
  50. }
RAW Paste Data
Pastebin PRO Summer Special!
Get 60% OFF on Pastebin PRO accounts!
Top