17 de out de 2011

Leds + Potenciometro+ Arduino

Leds sequenciais com Velocidade Controlada Pelo Potenciometro


Material:
 1x  Arduino(qualquer modelo)
10x Leds (qualquer cor)
10x Resistores de 220Ω(opcional)
1x   Potenciometro

Esquema:


Codigo IDE Arduino:






// these constants won't change:
const int analogPin = 0;   // the pin that the potentiometer is attached to
const int ledCount = 10;    // the number of LEDs in the bar graph

int ledPins[] = {
  2, 3, 4, 5, 6, 7,8,9,10,11 };   // an array of pin numbers to which LEDs are attached

int Estado=0;

void setup() {
  // loop over the pin array and set them all to output:
  for (int thisLed = 0; thisLed < ledCount; thisLed++) {
    pinMode(ledPins[thisLed], OUTPUT);
  }
}

void loop() {
  // read the potentiometer:
  int sensorReading = analogRead(analogPin);
  // map the result to a range from 0 to the number of LEDs:
  int ledLevel = map(sensorReading, 0, 1020, 0, 500);

/*
  // loop over the LED array:
  for (int thisLed = 0; thisLed < ledCount; thisLed++) {
    // if the array element's index is less than ledLevel,
    // turn the pin for this element on:
    if (thisLed < ledLevel) {
      digitalWrite(ledPins[thisLed], LOW);
    }
    // turn off all pins higher than the ledLevel:
    else {
      digitalWrite(ledPins[thisLed], HIGH);
    }
  }
  */
    // loop over the LED array:
   
 
      for (int i = 0; i < ledCount+1; i++){
         digitalWrite(ledPins[i], LOW);
         delay(ledLevel);
      }
       delay(10);
         for (int i = 10; i >= 0; i--){
         digitalWrite(ledPins[i], HIGH);
         delay(ledLevel);
     }  
}





Video :






video







Nenhum comentário:

Postar um comentário