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
- se puede cambiar el sensor por ultrasonido. Que debería cambiar tanto en programación como en conexión
- 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
- se podría incorporar 2 tiras de led rgb con 4 pines. . Si es si donde se conectarían con arduino
- se podría incorporar sonido con archivo avi o wav
Gracias por adelantado
[pre][color=#f8f8f2][color=#bc9458]
[/color][/color][/pre]
[pre][color=#f8f8f2][color=#bc9458]/* [/color]
[color=#bc9458] Code for automatic table soccer counter. By teacher Morgenthaler and student Leo at Swiss school www.oszt.ch[/color]
[color=#bc9458]*/[/color]
[color=#bc9458]// 3 lines importing libraries for the Adafruit display [/color]
[color=#cc7833]#include[/color] <Wire.h>
[color=#cc7833]#include[/color] <Adafruit_GFX.h>
[color=#cc7833]#include[/color] "Adafruit_LEDBackpack.h"
[color=#bc9458]// Initailizing the 7-segment display [/color]
Adafruit_7segment matrix = Adafruit_7segment();
[color=#bc9458]// Defining varialbes for the two goals[/color]
int Rot;
int Blau;
[color=#bc9458]// Defining Arduino's board-LED. For controlling purpose only during coding[/color]
[color=#cc7833]#define LEDPIN 13 [/color]
[color=#bc9458]// Defining the two pins the data connections of the breakbeam sensors [/color]
[color=#cc7833]#define SENSORPIN 4 [/color]
[color=#cc7833]#define SENSORPIN2 2 [/color]
[color=#bc9458]// Defining the pin for the back to zero button [/color]
[color=#cc7833]#define SENSORPIN3 7 [/color]
[color=#bc9458]// Initalizing and defining states for the breakbeam sensors and the back to zero button [/color]
int sensorState = [color=#6c99bb]0[/color], lastState=[color=#6c99bb]0[/color];
int sensorState2 = [color=#6c99bb]0[/color], lastState2=[color=#6c99bb]0[/color];
int sensorState3 = [color=#6c99bb]0[/color], lastState3=[color=#6c99bb]0[/color];
void setup() {
[color=#bc9458]// Initializing Arduino's board LED for output [/color]
pinMode(LEDPIN, OUTPUT);
[color=#bc9458]// Initializing pin for input from breakbeam sensor [/color]
pinMode(SENSORPIN, INPUT);
[color=#bc9458]// Activating the pullup resistor for this pin to make the two sensor states clear for Arduino [/color]
digitalWrite(SENSORPIN, HIGH);
[color=#bc9458]// Same for other breakbeam sensor[/color]
pinMode(SENSORPIN2, INPUT);
digitalWrite(SENSORPIN2, HIGH);
[color=#bc9458]// Same for back to zero button[/color]
pinMode(SENSORPIN3, INPUT);
digitalWrite(SENSORPIN3, HIGH);
[color=#bc9458]// Start value for goals[/color]
Rot = [color=#6c99bb]0[/color];
Blau = [color=#6c99bb]0[/color];
[color=#bc9458]//Define address for display[/color]
matrix.begin([color=#6c99bb]0x70[/color]);
}
void loop(){
[color=#bc9458]// Next 3 lines: Read and save states of the 2 sensors and the back to zero button [/color]
sensorState = digitalRead(SENSORPIN);
sensorState2 = digitalRead(SENSORPIN2);
sensorState3 = digitalRead(SENSORPIN3);
[color=#bc9458]// The following lines are for displaying the the goal values on the display.[/color]
[color=#bc9458]// This if argument prevents from displaying a zero with numbers under 10[/color]
[color=#cc7833]if[/color](Rot / [color=#6c99bb]10[/color])
[color=#bc9458]// Display position 0 will show the first position of goal variable Rot[/color]
matrix.writeDigitNum([color=#6c99bb]0[/color], (Rot / [color=#6c99bb]10[/color]) );
[color=#bc9458]// Display position 1 will show the second position of goal variable Rot [/color]
matrix.writeDigitNum([color=#6c99bb]1[/color], Rot % [color=#6c99bb]10[/color] );
[color=#bc9458]// A colon will be displayed between the two varialbes [/color]
matrix.drawColon([color=#b83426]true[/color]);
[color=#bc9458]// This if argument prevents from displaying a zero for other variable [/color]
[color=#cc7833]if[/color](Blau / [color=#6c99bb]10[/color])
[color=#bc9458]// Display position 3 will show the first position of goal variable Blau [/color]
matrix.writeDigitNum([color=#6c99bb]3[/color], (Blau / [color=#6c99bb]10[/color]) );
[color=#bc9458]// Display position 4 will show the second position of goal variable Blau [/color]
matrix.writeDigitNum([color=#6c99bb]4[/color], Blau % [color=#6c99bb]10[/color] );
[color=#bc9458]// Display everyting above [/color]
matrix.writeDisplay();
[color=#bc9458]// 3 if-else arguments following for the two breakbeam sensors and the back to zero button [/color]
[color=#bc9458]// If sensor light beam is broken, system reads status low and turns the control LED on [/color]
[color=#cc7833]if[/color] (sensorState == LOW) {
digitalWrite(LEDPIN, HIGH);
}
[color=#bc9458]// otherwise no power for the control LED[/color]
[color=#cc7833]else[/color] {
digitalWrite(LEDPIN, LOW);
}
[color=#bc9458]// If SensorState does not differ from lastState...[/color]
[color=#bc9458]// (The "!" reverses the signal state to function correclty.[/color]
[color=#bc9458]// Without it, the goal values constantly increase when light beams ar UNbroken)[/color]
[color=#cc7833]if[/color] (sensorState && !lastState) {
[color=#bc9458]// ...The message Unbroken would be displayed on Arduino's serial monitor [/color]
Serial.println([color=#a5c261]"1 Unbroken"[/color]);
}
[color=#bc9458]// If it differs, "Broken" would be displayed and the goal variable Red is increased. [/color]
[color=#cc7833]if[/color] (!sensorState && lastState) {
Serial.println([color=#a5c261]"1 Broken"[/color]);
Rot = Rot + [color=#6c99bb]1[/color];
}
[color=#bc9458]// Same for other breakbeam sensor[/color]
[color=#cc7833]if[/color] (sensorState2 && !lastState2) {
Serial.println([color=#a5c261]"2 Unbroken"[/color]);
}
[color=#cc7833]if[/color] (!sensorState2 && lastState2) {
Serial.println([color=#a5c261]"2 Broken"[/color]);
Blau = Blau + [color=#6c99bb]1[/color];
}
[color=#bc9458]// Check status of back to zero button [/color]
[color=#cc7833]if[/color] (sensorState3 && !lastState3) {
}
[color=#bc9458]// If pressed, the serial display would show "reset" and both goal variables are reset to zero.[/color]
[color=#cc7833]if[/color] (!sensorState3 && lastState3) {
Serial.println([color=#a5c261]"reset"[/color]);
Blau = [color=#6c99bb]0[/color];
Rot = [color=#6c99bb]0[/color];
[color=#bc9458]// Clears everything displayed on LED[/color]
matrix.clear();
}
[color=#bc9458]// Save the last sensor states [/color]
lastState = sensorState;
lastState2 = sensorState2;
lastState3 = sensorState3;
}
[color=#bc9458]// End of programm. Restart void loop[/color][/color][/pre]

