Contador para marcador
Publicado por Jesus (4 intervenciones) el 30/12/2020 10:52:04
Buenos días
Estoy intentando hacer un proyecto que consiste en un marcador con 2 displays de 7 segmentos a través de 2 sensores ultrasonido
Buscando y buscando me he encontrado con este código que adjunto, que cubre el 70% de mis objetivos
Mi pregunta es
1) se puede cambiar el sensor por ultrasonido. Que debería cambiar tanto en programación como en conexión
2) se puede cambiar el display por 2 display de 1 dígito de 7 segmentos . Que debería cambiar tanto en programación como en conexión
3) se podría incorporar 2 tiras de led rgb con 4 pines. . Si es si donde se conectarían con arduino
4) se podría incorporar sonido con archivo avi o wav
Gracias por adelantado

Estoy intentando hacer un proyecto que consiste en un marcador con 2 displays de 7 segmentos a través de 2 sensores ultrasonido
Buscando y buscando me he encontrado con este código que adjunto, que cubre el 70% de mis objetivos
Mi pregunta es
1) se puede cambiar el sensor por ultrasonido. Que debería cambiar tanto en programación como en conexión
2) se puede cambiar el display por 2 display de 1 dígito de 7 segmentos . Que debería cambiar tanto en programación como en conexión
3) se podría incorporar 2 tiras de led rgb con 4 pines. . Si es si donde se conectarían con arduino
4) se podría incorporar sonido con archivo avi o wav
Gracias por adelantado
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
Code for automatic table soccer counter. By teacher Morgenthaler and student Leo at Swiss school www.oszt.ch
*/
// 3 lines importing libraries for the Adafruit display
#include <Wire.h>
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"
// Initailizing the 7-segment display
Adafruit_7segment matrix = Adafruit_7segment();
// Defining varialbes for the two goals
int Rot;
int Blau;
// Defining Arduino's board-LED. For controlling purpose only during coding
#define LEDPIN 13
// Defining the two pins the data connections of the breakbeam sensors
#define SENSORPIN 4
#define SENSORPIN2 2
// Defining the pin for the back to zero button
#define SENSORPIN3 7
// Initalizing and defining states for the breakbeam sensors and the back to zero button
int sensorState = 0, lastState=0;
int sensorState2 = 0, lastState2=0;
int sensorState3 = 0, lastState3=0;
void setup() {
// Initializing Arduino's board LED for output
pinMode(LEDPIN, OUTPUT);
// Initializing pin for input from breakbeam sensor
pinMode(SENSORPIN, INPUT);
// Activating the pullup resistor for this pin to make the two sensor states clear for Arduino
digitalWrite(SENSORPIN, HIGH);
// Same for other breakbeam sensor
pinMode(SENSORPIN2, INPUT);
digitalWrite(SENSORPIN2, HIGH);
// Same for back to zero button
pinMode(SENSORPIN3, INPUT);
digitalWrite(SENSORPIN3, HIGH);
// Start value for goals
Rot = 0;
Blau = 0;
//Define address for display
matrix.begin(0x70);
}
void loop(){
// Next 3 lines: Read and save states of the 2 sensors and the back to zero button
sensorState = digitalRead(SENSORPIN);
sensorState2 = digitalRead(SENSORPIN2);
sensorState3 = digitalRead(SENSORPIN3);
// The following lines are for displaying the the goal values on the display.
// This if argument prevents from displaying a zero with numbers under 10
if(Rot / 10)
// Display position 0 will show the first position of goal variable Rot
matrix.writeDigitNum(0, (Rot / 10) );
// Display position 1 will show the second position of goal variable Rot
matrix.writeDigitNum(1, Rot % 10 );
// A colon will be displayed between the two varialbes
matrix.drawColon(true);
// This if argument prevents from displaying a zero for other variable
if(Blau / 10)
// Display position 3 will show the first position of goal variable Blau
matrix.writeDigitNum(3, (Blau / 10) );
// Display position 4 will show the second position of goal variable Blau
matrix.writeDigitNum(4, Blau % 10 );
// Display everyting above
matrix.writeDisplay();
// 3 if-else arguments following for the two breakbeam sensors and the back to zero button
// If sensor light beam is broken, system reads status low and turns the control LED on
if (sensorState == LOW) {
digitalWrite(LEDPIN, HIGH);
}
// otherwise no power for the control LED
else {
digitalWrite(LEDPIN, LOW);
}
// If SensorState does not differ from lastState...
// (The "!" reverses the signal state to function correclty.
// Without it, the goal values constantly increase when light beams ar UNbroken)
if (sensorState && !lastState) {
// ...The message Unbroken would be displayed on Arduino's serial monitor
Serial.println("1 Unbroken");
}
// If it differs, "Broken" would be displayed and the goal variable Red is increased.
if (!sensorState && lastState) {
Serial.println("1 Broken");
Rot = Rot + 1;
}
// Same for other breakbeam sensor
if (sensorState2 && !lastState2) {
Serial.println("2 Unbroken");
}
if (!sensorState2 && lastState2) {
Serial.println("2 Broken");
Blau = Blau + 1;
}
// Check status of back to zero button
if (sensorState3 && !lastState3) {
}
// If pressed, the serial display would show "reset" and both goal variables are reset to zero.
if (!sensorState3 && lastState3) {
Serial.println("reset");
Blau = 0;
Rot = 0;
// Clears everything displayed on LED
matrix.clear();
}
// Save the last sensor states
lastState = sensorState;
lastState2 = sensorState2;
lastState3 = sensorState3;
}
// End of programm. Restart void loop

Valora esta pregunta


0