Arduino - Taller de Introducción A La Ingeniería

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

ARDUINO

TALLER DE INTRODUCCIÓN A LA INGENIERÍA

PROF: LUIS MUÑOZ JARAMILLO


Equipamiento
Interfaz de Software
ESQUEMA BÁSICO
PRIMER PROGRAMA
PROGRAMA
int led = 6;

void setup() {                
  pinMode(led, OUTPUT);    
}

void loop() {
  digitalWrite(led, HIGH);
  delay(1000);            
  digitalWrite(led, LOW);  
  delay(1000);          
}
PROGRAMA BOTÓN
const int buttonPin = 2;  
const int ledPin =  6;      

int buttonState = 0;

void setup() {
  pinMode(ledPin, OUTPUT);      
  pinMode(buttonPin, INPUT);    
}

void loop(){
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) {    
    digitalWrite(ledPin, HIGH);  
  }
  else {
    digitalWrite(ledPin, LOW);
  }
}
CONTADOR BINARIO
int outPin[] = {7, 6, 5, 4};

int delayValue = 600;

void setup()
{
int i = 0;
for ( i = 0; i < 4; i++)
pinMode(outPin[i], OUTPUT);
}

void loop()
{
int i = 0, j=0;

for ( i = 0; i < 16; i++)


{
for ( j = 0; j < 4; j++)
{
if ( ( (i >> j) & 1 ) == 1 )
digitalWrite(outPin[j], HIGH);
else digitalWrite(outPin[j], LOW);
}
delay(delayValue);
}
}
ON/OFF BOTON
int pulsador=2;
int led=6;
int estado;

void setup()
{
pinMode(pulsador, INPUT);
pinMode(led,OUTPUT);
}

void loop()
{
delay(100);
estado = LOW;
estado = digitalRead(pulsador);
while(estado == HIGH)
{
delay(100);
if(digitalRead(pulsador)==LOW)
{
estado = HIGH;
digitalWrite(led,HIGH);
}
else
{
estado = LOW;
digitalWrite(led,LOW);
}
}
}
SECUENCIA
int timer = 100;

void setup() {
for (int thisPin = 4; thisPin < 8; thisPin++) {
pinMode(thisPin, OUTPUT);
}
}

void loop() {
// loop from the lowest pin to the highest:
for (int thisPin = 4; thisPin < 8; thisPin++) {
digitalWrite(thisPin, HIGH);
delay(timer);
digitalWrite(thisPin, LOW);
}

for (int thisPin = 7; thisPin >= 3; thisPin--) {


digitalWrite(thisPin, HIGH);
delay(timer);
digitalWrite(thisPin, LOW);
}
}
SENSOR
const int sensorMin = 0;
const int sensorMax = 600;

void setup() {
Serial.begin(9600);
for (int thisPin = 4; thisPin < 8; thisPin++) {
pinMode(thisPin, OUTPUT);
}

void loop() {
int sensorReading = analogRead(A0);
int range = map(sensorReading, sensorMin, sensorMax, 0, 3);

switch (range) {
case 0: // MANO EN EL SENSOR
//Serial.println("dark");
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
break;
case 1: // MANO MUY CERCA DEL SENSOR
//Serial.println("dim");
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
break;
case 2: // MANO CERCA DEL SENSOR
//Serial.println("medium");
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
break;
case 3: // MANO LEJOS DEL SENSOR
//Serial.println("bright");
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
break;
}
delay(1);
}

You might also like