1.Descripción del Laboratorio
Controlar 8 LEDs desde el Arduino, a través de un IC 74HC595, definiendo mínimo 8 patrones de movimiento que son controlados desde una interfaz gráfica en Processing/ControlP5.
Controlar 8 LEDs desde el Arduino, a través de un IC 74HC595, definiendo mínimo 8 patrones de movimiento que son controlados desde una interfaz gráfica en Processing/ControlP5.
2.Elementos Utilizados
v1 Computador
v1 Protoboard
v1 Arduino UNO
v Resistencias
vLeds
vCable
vSoftware “Arduino”
vSoftware “Fritzing”
v IC 74HC595
Processing
3.Diagrama del Montaje
4.Diagrama Esquemático
6.Video del funcionamiento
7.Codigo Fuente Arduino y Processing
1.#define PIN 3
2.
3.
4. const int Latch = 8;
5. const int Clock = 9;
6. const int Data = 7;
7.
8. int Pins[PIN] = {
9. 7,8,9};
10.
11.
12. int Lect = 0;
13. boolean OnLed = false;
14. int Dato = 0;
15. int i = 0;
16. int Led[]={1,2,4,8,16,32,64,128};
17.
18.
19. void setup() {
20. for (int j=0; j<PIN; j++){
21. pinMode(Pins[j], OUTPUT);
22. }
23.
24. Serial.begin(9600);
25. }
26.
27.
28. void loop()
29. {
30. if (Serial.available()>0) {
31.
32. Lect = Serial.read();
//Leemos el Dato
33.
34.
35. if (OnLed)
36. {
37. Suma(Lect);
38. On(Dato);
39. OnLed = false;
40. }
41. else
42. {
43.
44. i = Lect;
45. OnLed = true;
46. }
47. }
48. }
49.
50.
51. void Suma(int estadoLED){
52. if(estadoLED==0)
53. {
54. Dato = Dato-Led[i];
55. }else{
56. Dato = Dato+Led[i];
57. }
58. }
59.
60.
61. void On(int Valor)
62. {
63. digitalWrite(Latch, LOW);
64. shiftOut(Data, Clock, MSBFIRST, Valor);
65. digitalWrite(Latch, HIGH);
66. }
1. import controlP5.*;
2. import processing.serial.*;
3.
4.
5. ControlP5 cP5;
6.
7.
8. Serial serial;
9.
10. int[] led = new int[] {
11. 0, 0, 0, 0, 0, 0, 0, 0
12. };
13.
14.
15. void setup() {
16. size(590, 250); //Tamaño
de la ventana
17. noStroke();
18.
19. cP5 = new ControlP5(this);
//Crea el objeto ControlP5
20.
21. // Crea el Knob del color Rojo
22. for (int i=0;
i<led.length; i++)
23. {
24. cP5.addToggle("led"+i, 35+i*70, 140, 30, 30)
25. .setMode(ControlP5.SWITCH);
26. }
27.
28. String puerto =
Serial.list()[0];
29.
30. serial = new Serial(this, puerto, 9600);
31. }
32.
33.
34. void draw() {
35. background(0xFF444444);
36. fill(led[0] == 0 ? 0xFF222222 :
color(255, 255, 0));
37. ellipse(50, 100, 50, 50);
38. for (int i=1; i<4; i++) {
39. fill(led[i] == 0 ? 0xFF222222 : color(255, 0, 0));
40. ellipse(50+i*70, 100, 50, 50);
41. }
42. for (int i=4; i<led.length; i++) {
43. fill(led[i] == 0 ? 0xFF222222 : color(0, 255, 0));
44. ellipse(50+i*70, 100, 50, 50);
45. }
46. fill(255);
47. textFont(createFont("Gill Sans Ultra Bold", 50));
48. text("Enciende un LED", 40, 50);
49. fill(255);
50. textSize(25);
51. text("", 120,
230);
52. }
53.
54. /
55. void controlEvent(ControlEvent evento)
{
56. String nombre = evento.getController().getName();
57. int valor = int(evento.getController().getValue());
58.
59. // Guarda el valor de cada boton
60. for (int i=0;
i<led.length; i++) {
61. if (nombre.equals("led"+i)) {
62. led[i] = valor;
63. serial.write(i);
64.
serial.write(valor);
65.
println("evento: " + i + " / valor: "+valor);
66. }
67. }
68. }
No hay comentarios:
Publicar un comentario