1 / 9

/* Blink Enciende y apaga un LED */ void setup () {

/* Blink Enciende y apaga un LED */ void setup () { // El 13 debe tener un led conectado a el, en la mayoría de arduinos ya hay uno pinMode (13, OUTPUT); // Iniciar el pin 13 como una salida } void loop () { digitalWrite (13, HIGH); // Prende el LED

carrie
Download Presentation

/* Blink Enciende y apaga un LED */ void setup () {

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. /* Blink Enciende y apaga un LED */ voidsetup() { // El 13 debe tener un led conectado a el, en la mayoría de arduinos ya hay uno pinMode(13, OUTPUT); // Iniciar el pin 13 como una salida } voidloop() { digitalWrite(13, HIGH); // Prende el LED delay(1000); // Espera un sagundo digitalWrite(13, LOW); // Apaga el LED delay(1000); // Espera un segundo }

  2. /* Leer valod digital Lee el valor de una entrada digital en el pin2 y muestra el valor por medio de comunicación serial. */ voidsetup() { Serial.begin(9600); //inicia la comunicación serial pinMode(2, INPUT); // inicia el pin 2 como entrada } voidloop() { intsensorValue = digitalRead(2); //lee el valor del pin 2 Serial.println(sensorValue, DEC); //envía el valor del pin dos mediante comunicación serial }

  3. /*Boton Prende y apaga un LED conectado al pin 13 cuando se presiona un botón en el pin 2 */intboton = 2;     // el numero del pin donde está el botónintled =  13;      // el numero donde esta el LEDint estado = 0;   // variable con el estado del botónvoidsetup() {pinMode(led, OUTPUT);      //iniciamos el pin del LED como salidapinMode(boton, INPUT);   //iniciamos el pin del botón como entrada  }voidloop(){  estado = digitalRead(boton); //leemos el estado del botónif (estado== HIGH) {     //miramos si el botón está presionado  digitalWrite(led, HIGH);  //si sí está presionado, prendemos el LED  } else { //si no está presionado, apagamos el LEDdigitalWrite(led, LOW);   }}

  4. /*potenciómetrolee el valor de un potenciómetro */ int entrada = A0; // entrada a la que está conectado el potenciómetro int sensor= 0; // valor que se lee de el puesto de entrada int salida= 0; // valor de salida convertido a escala de 0 a 255 voidsetup() { Serial.begin(9600); // iniciamos comunicación con el computador } voidloop() { sensor = analogRead(entrada); // leemos el valor de entrada salida= map(sensor, 0, 1023, 0, 255); // Cambiamos la escala // le enviamos los datos al computador Serial.print("sensor = " ); Serial.print(sensor); Serial.print("\t salida = "); Serial.println(salida); delay(100); //hacemos una pausa de 100 milisegundos }

  5. Arduino Processing importprocessing.serial.*; float fondo = 0; Serial myPort; voidsetup() { size(200, 200); println(Serial.list()); myPort= new Serial(this, Serial.list()[0], 9600); myPort.bufferUntil('\n'); } voiddraw() { background(fondo); } voidserialEvent(Serial myPort) { Stringentrada = myPort.readStringUntil('\n'); fondo = float(entrada); println(float(entrada)); } /*potenciómetrolee el valor de un potenciómetro */ int entrada = A0; int sensor= 0; int salida= 0; voidsetup() { Serial.begin(9600); } voidloop() { sensor = analogRead(entrada); salida= map(sensor, 0, 1023, 0, 255); // le enviamos los datos al computador Serial.print("sensor = " ); Serial.print(sensor); Serial.print("\t salida = "); Serial.println(salida); delay(100); }

  6. Arduino Processing importprocessing.serial.*; Serial myPort; voidsetup() { size(256, 150); println(Serial.list()); myPort = new Serial(this, Serial.list()[0], 9600); } voiddraw() { for (int i = 0; i < 256; i++) { stroke(i); line(i, 0, i, 150); } myPort.write(mouseX); } intledPin = 9; void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); } void loop() { byte brillo; if (Serial.available()) { brillo= Serial.read(); analogWrite(ledPin, brillo); } }

More Related