lunes, 23 de diciembre de 2013

una suerte de morse

Este es un pequeño codigo que simplemente toma un caracter del serial monitor y apaga (-) o prende (.) el led que el arduino trae built-in.





// constants won't change. Used here to
// set pin numbers:
 
const int ledPin =  13;      // the number of the LED pin

// Variables will change:
int ledState = 0;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.


long interval = 100; // interval at which to blink (milliseconds)

char inByte; //input from serial


void setup() {

  Serial.begin(9600);//set input speed
 
}

void loop()
{
 
    if ( Serial.available()>0 )
    {
      inByte = Serial.read();
     
      switch (inByte) {
     
        case '.': ledState=255;break;
        case '-': ledState=0;break;
       
      }
    
      Serial.print(inByte);
     
      analogWrite(ledPin, ledState);
      delay(interval);
     
  }
   
   
   
}

No hay comentarios:

Publicar un comentario