articles_code / arduino_article / listing4.pde

/* Flex sensor + LED 
/* Analog Input
* Demonstrates analog input by reading an analog sensor on analog
* pin 0 and turning on and off a light emitting diode(LED) connected to
  digital pin 13.
* The amount of time the LED will be on and off depends on the value obtained by
* analogRead().
* Created by David Cuartielles
* Modified 16 Jun 2009
* By Tom Igoe
* Modified 16 July, 2011
* By Amit Saha
* Current code was tested with a Flex sensor
int sensorPin = 0; /*Flex sensor pin */
int ledPin = 13; /* LED pin*/

void setup() {
  pinMode(ledPin, OUTPUT);

void loop() {
  int loop=1;
  float sensorValues=0.0,delaytime;
  for(loop=1;loop <=10 ;loop++)
     sensorValues = sensorValues + analogRead(sensorPin);
  //Use the average as a delay value
  delaytime = sensorValues/10;
  digitalWrite(ledPin, HIGH);
  digitalWrite(ledPin, LOW);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.