Vous êtes sur la page 1sur 4

1.ENCENDIDO Y APAGADO DE MOTOR DC CON INVERSIÓN DE GIRO.

int P2=1;
float analog=0;
float valor;
int x=3;
void setup() {
// put your setup code here, to run once:
pinMode(P1,INPUT_PULLUP);
pinMode(P2,INPUT_PULLUP);
Timer1.initialize(1000);
}

void loop() {
valor=analogRead(analog);
P1=digitalRead(0);
P2=digitalRead(1);
if(P1==0||x==0){
x=0;
Timer1.pwm(9,valor);
Timer1.pwm(10,0);
}
if(P2==0||x==1){
x=1;
Timer1.pwm(10,valor);
Timer1.pwm(9,0);
}
}

2. SERVOMOTOR EN 0, 90 Y 180º.CONTROLA CON SEÑAL PWM.

#include<TimerOne.h>
int analog=0;
float valor;
float conversion;
void setup() {

Timer1.initialize(25000);
}
void loop() {
// put your main code here, to run repeatedly:
valor= analogRead(analog);
conversion=valor*2500/25000;
Timer1.pwm(9,conversion);
}
3. MOTOR PAP
int x=0;
int dere=0;
int izq=1;
int apag=2;
const int giro[]={12,6,3,9};

void lectura(int valor){


digitalWrite(10,bitRead(valor,0));
digitalWrite(11,bitRead(valor,1));
digitalWrite(12,bitRead(valor,2));
digitalWrite(13,bitRead(valor,3));
}

void setup() {
// put your setup code here, to run once:
pinMode(dere,INPUT_PULLUP);
pinMode(izq,INPUT_PULLUP);
pinMode(apag,INPUT_PULLUP);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
int avance;
dere=digitalRead(0);
izq=digitalRead(1);
apag=digitalRead(2);

if(dere==0||x==1){
if(x==0|| x==3){x=1;}
avance=0;
for(avance=0;avance<=3;avance++){
lectura(giro[avance]);
delay(160);
apag=digitalRead(2);
if(apag==0){
avance=4;
x=3;
lectura(0);
}
}
}

if(izq==0||x==2){
if(x==0|| x==3){x=2;}
avance=3;
for(avance=3;avance>=0;avance--){
lectura(giro[avance]);
delay(160);
//dere=digitalRead(0);
// if(dere==0){avance=-1;}
apag=digitalRead(2);
if(apag==0){
avance=-1;
x=3;
lectura(0);
}
}}
}
ADC (CONVERSION DE VALORES)
#include <LiquidCrystal.h> //Libreria para manejar el LCD
LiquidCrystal LCD(12, 11, 5, 4, 3, 2); //Definición de pines para conectar el LCD (RS, E, D4, D5, D6, D7)
int analog=0; //Define el pin 0 como "analog"
int valor;
int conversion;
void setup()
{
LCD.begin(16, 2); //Tipo de LCD
}
void loop()
{
valor=analogRead(analog); //lee el pin 0 y lo asigna a la variable valor
conversion=valor*5/1023;
LCD.clear();
LCD.setCursor(5,0); //Columna 0, fila 0
LCD.print("ADC");
LCD.setCursor(5, 1); //Columna 5 fila 2
LCD.print(conversion, 2);
delay(200);
}

PWM- SALIDA ANALÓGICA


//PWM-GENERA UNA ONDA DE 500 Hz
//EL PERIODO ESTÁ DEFINIDO EN 200 ms.
int led=10; //define el pin 10 como "led"
int valor=64; //define la variable "valor"

void setup()
{
//No es necesario configurar entradas y salidas
}

void loop()
{
analogWrite(led, valor); //Escribe en el pin 10 valor
}
INTERRUPCION (CONTADOR DISPLAY)
const int decoder[]={64,121,36,36,48,25,18,3,120,0,24};
#include <TimerOne.h>
int led = 13;
int pulsador =2;
volatile int estado = LOW;
int decena=0;
void setup() {
pinMode(pulsador, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(pulsador),ManejadorPulsador,FALLING);
Timer1.initialize(800000);
Timer1.attachInterrupt(callback);
int pin;
for(pin=6;pin<=12;pin++)
{
pinMode(pin,OUTPUT);
} }
void callback(){
if(decena <=10){
display7(decoder[decena]);
decena++;
}
if(decena ==11){
decena =0;
} }
void ManejadorPulsador(){
estado= !estado;
decena =0;}
void display7(int valor){
digitalWrite(6, bitRead(valor, 0));
digitalWrite(7, bitRead(valor, 1));
digitalWrite(8, bitRead(valor, 2));
digitalWrite(9, bitRead(valor, 3));
digitalWrite(10, bitRead(valor, 4));
digitalWrite(11, bitRead(valor, 5));
digitalWrite(12, bitRead(valor, 6));
}

SERVO MOTOR SEÑAL PWM


#include <Servo.h>
int analog=0;
float valor;
int control=9;
Servo servo1;
void setup() {
servo1.attach(control);
}
void loop() {
valor = analogRead(analog);
valor= valor*180/1023;
servo1.write(valor);

Vous aimerez peut-être aussi