sábado, 8 de febrero de 2014

Oscilador lineal

el siguiente programa controla el motor DC de una impresora a través de la señal de un potenciómetro

const int LeftAnalogOutPin = 9;
const int RightAnalogOutPin = 10;
int outputValue = 0;
int TiempoQueDuraLaCondicion =1;
//int Incrementos=8;
int sensorPin=A0;
int sensorValue=0;

void setup() { }
void loop() {
  sensorValue = analogRead(sensorPin);
  int Incrementos=map(sensorValue,0,1023,2,10);
  for (int thisPin = 41; thisPin <= 255; thisPin+=Incrementos+1) {
    outputValue = thisPin;
    analogWrite(LeftAnalogOutPin,outputValue);  
    delay(TiempoQueDuraLaCondicion);                
  }
   for (int thisPin = 255; thisPin >= 1; thisPin-=Incrementos) {
    outputValue = thisPin;
    analogWrite(LeftAnalogOutPin,outputValue);  
    delay(TiempoQueDuraLaCondicion);
  }
  analogWrite(LeftAnalogOutPin,0);
  for (int thisPin = 41; thisPin <= 255; thisPin+=Incrementos+2) {
    outputValue = thisPin;
    analogWrite(RightAnalogOutPin,outputValue);  
    delay(TiempoQueDuraLaCondicion);                
  }
  for (int thisPin = 255; thisPin >= 1; thisPin-=Incrementos) {
    outputValue = thisPin;
    analogWrite(RightAnalogOutPin,outputValue);  
    delay(TiempoQueDuraLaCondicion);
  }                  
  analogWrite(RightAnalogOutPin,0);
}

No hay comentarios:

Publicar un comentario