0% found this document useful (0 votes)
27 views6 pages

Practica 1 Processing

The document describes a project to control a stepper motor using an Arduino board. It includes: 1) The names of the team members and a link to a video demonstration. 2) Details of the Arduino code, which uses buttons and serial communication to control the stepping motor and four LEDs in sequence. 3) A Processing program for the human-machine interface (HMI), which displays control buttons and motor position indicators.

Uploaded by

Crystian Chavez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views6 pages

Practica 1 Processing

The document describes a project to control a stepper motor using an Arduino board. It includes: 1) The names of the team members and a link to a video demonstration. 2) Details of the Arduino code, which uses buttons and serial communication to control the stepping motor and four LEDs in sequence. 3) A Processing program for the human-machine interface (HMI), which displays control buttons and motor position indicators.

Uploaded by

Crystian Chavez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Equipo 1:

Anguiano Escobar Alondra Citlali


Chávez Jiménez Crystian Alonso
Hernández Gaona Víctor Nathanel
Pereda Flores Josselyn
Video de funcionamiento

https://youtu.be/83ujkuWpu-Q?si=9QBCGiYy2pBN0V78

Conexión Arduino:

Código Arduino:

int p=3;
int a=2;
int b1=4;
int b2=5;
int b3=6;
int b4=7;
int set=0;
int i=0;

void setup()
{
Serial.begin(9600);
pinMode(p,INPUT);
pinMode(a,INPUT);
pinMode(b1,OUTPUT);
pinMode(b2,OUTPUT);
pinMode(b3,OUTPUT);
pinMode(b4,OUTPUT);
}

void loop()
{
if(Serial.available())
{
char opt=Serial.read();
if((digitalRead(a)==1) || (opt=='a'))
{
set=1;
delay(10);
}
if((digitalRead(p)==1) || (opt=='p'))
{
set=0;
delay(10);
}
pasos(opt);
}

}
void pasos(char o)
{
switch (o)
{
case '1':
digitalWrite(b1,HIGH);
digitalWrite(b2,LOW);
digitalWrite(b3,LOW);
digitalWrite(b4,LOW);
delay(500);
break;
case '2':
digitalWrite(b1,LOW);
digitalWrite(b2,HIGH);
digitalWrite(b3,LOW);
digitalWrite(b4,LOW);
delay(500);
break;
case '3':
digitalWrite(b1,LOW);
digitalWrite(b2,LOW);
digitalWrite(b3,HIGH);
digitalWrite(b4,LOW);
delay(500);
break;
case '4':
digitalWrite(b1,LOW);
digitalWrite(b2,LOW);
digitalWrite(b3,LOW);
digitalWrite(b4,HIGH);
delay(500);
break;
default:
digitalWrite(b1,LOW);
digitalWrite(b2,LOW);
digitalWrite(b3,LOW);
digitalWrite(b4,LOW);
delay(500);
break;
}
}

HMI generada en processing:

Codigo Processing

import processing.serial.*;
Serial serie;
boolean A=false;
boolean B=false;
color Aact=color(200,200,0);
color Ades=color(0,200,0);
color Pact=color(200,0,0);
color Pdes=color(0,200,0);
PFont font12;
int i=0;
void setup()
{
size(800,400);
font12=createFont("Arial",16);
textFont(font12);
serie=new Serial(this,Serial.list()[0],9600);
textAlign(CENTER, CENTER);
text("Apagado",210,100);
text("Activo",200,100);
fondo();
}
void draw()
{
float distancia = dist (100, 100, mouseX, mouseY);
if (distancia < 50)
{
if (!mousePressed) {
fill(0,255,0);
ellipse(100,100,100,100);
A=true;
serie.write("a");
}else
{
fill(0,129,0);
ellipse(100,100,100,100);
}
}
float distancia2 = dist (100, 300, mouseX, mouseY);
if (distancia2 < 50)
{
if (!mousePressed) {
fill(255,0,0);
ellipse(100,300,100,100);
A=false;
serie.write("p");
}else
{
fill(200,0,0);
ellipse(100,300,100,100);
}
}
if(A) i++;
if(!A) i=0;
luces(i);
if(i==4) i=0;
textFont(font12, 16);
delay(1000);
}
void fondo()
{
background(0);
fill(155,156,155);
rect(10, 10, 290, 380);
rect(310, 10, 480, 380);
fill(255,255,255);
rect(155, 80, 90, 40);
rect(155, 280, 90, 40);
fill(192,192,192);
ellipse(100,100,105,105);
ellipse(100,300,105,105);
fill(100,100,0);

fill(0,0,0);
text("Arraque", 200, 100);
text("Paro", 200, 300);
fill(192,192,192);
rect(410, 30, 280, 80);
fill(0,0,0);
text("Anguiano Citlali", 550, 45);
text("Chavez Crystian", 550, 60);
text("Hernandez Nathanael", 550, 75);
text("Pereda Jocelin", 550, 90);
}
void luces(int o)
{
switch(o)
{
case 1:
serie.write("1");
fill(0,255,0);
ellipse(400,200,50,50);
fill(0,0,0);
ellipse(500,200,50,50);
ellipse(600,200,50,50);
ellipse(700,200,50,50);
break;
case 2:
serie.write("2");
fill(0,255,0);
ellipse(500,200,50,50);
fill(0,0,0);
ellipse(400,200,50,50);
ellipse(600,200,50,50);
ellipse(700,200,50,50);
break;
case 3:
serie.write("3");
fill(0,255,0);
ellipse(600,200,50,50);
fill(0,0,0);
ellipse(400,200,50,50);
ellipse(500,200,50,50);
ellipse(700,200,50,50);
break;
case 4:
serie.write("4");
fill(0,255,0);
ellipse(700,200,50,50);
fill(0,0,0);
ellipse(400,200,50,50);
ellipse(500,200,50,50);
ellipse(600,200,50,50);
break;
default:
serie.write("5");
fill(0,0,0);
ellipse(400,200,50,50);
ellipse(500,200,50,50);
ellipse(600,200,50,50);
ellipse(700,200,50,50);
break;
}
}

You might also like