Hallo.
Ich schreibe gerade an einem Programm, bei dem ein Master per I2c dem slave eine Variable übermittelt.
Der Slave soll dann diese Variable auf einer 7Segmentanzeige anzeigen. Dies tut er jedoch nicht.
Die Daten, also die Variable kommt definitiv an, deswegen lege ich den code des masters nicht bei, da es an dem slave liegt. An der Hardware liegt es auch nicht da die Segmentanzeige in einem anderen Code funktioniert.
#include <Wire.h>
const int Elemente[] = { 8, 7, 6, 5, 4, 3, 2 };
int score1 = 0;
int score2 = 0;
const int Anzeige1 = 9;
const int Anzeige2 = 10;
const int Lautsprecher = 11;
int notenNr = 0;
const int noten[] = { 262, 311, 330, 330, 415, 370, 415, 370, 466, 415, 466, 415, 370, 330, 311 };
const int dauer[] = { 220, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 215, 215, 215, 215 };
const int noten2[] = { 415, 370, 466, 330, 370, 494, 311, 523, 262, 523, 330, 415, 466, 262, 523 };
const int dauer2[] = { 220, 200, 220, 200, 220, 200, 220, 200, 220, 215, 215, 215, 200, 200, 200 };
unsigned long aktuell = 0;
unsigned long tonBeginn = 0;
unsigned long tonDauer = 0;
int Regler = A0;
int Rueckgabe = 0;
// x: 0 1 2 3 4 5 6 7 8 9
const int Status_a[] = {1, 0, 1, 1, 0, 1, 1, 1, 1, 1};
const int Status_b[] = {1, 1, 1, 1, 1, 0, 0, 1, 1, 1};
const int Status_c[] = {1, 1, 0, 1, 1, 1, 1, 1, 1, 1};
const int Status_d[] = {1, 0, 1, 1, 0, 1, 1, 0, 1, 1};
const int Status_e[] = {1, 0, 1, 0, 0, 0, 1, 0, 1, 0};
const int Status_f[] = {1, 0, 0, 0, 1, 1, 1, 0, 1, 1};
const int Status_g[] = {0, 0, 1, 1, 1, 1, 1, 0, 1, 1};
void setup() {
pinMode(Lautsprecher, OUTPUT);
Serial.begin(9600);
Wire.begin(8);
Wire.onReceive(receiveEvent);
Serial.begin(9600);
for (int x = 0; x < 7; x++) {
pinMode(Elemente[x], OUTPUT);
}
}
void loop() {
aktuell = millis();
Wire.begin(8);
Wire.onReceive(receiveEvent);
Rueckgabe = analogRead(Regler);
if (Rueckgabe > 0) {
switch (int(Rueckgabe / 205)) {
case 0:
noTone(11);
break;
case 1:
if (aktuell - tonBeginn > tonDauer ) {
tonBeginn = aktuell;
tone( Lautsprecher, noten[notenNr] );
tonDauer = dauer[notenNr];
notenNr++;
if ( notenNr == 15 )
notenNr = 0;
}
break;
case 2:
noTone(11);
break;
case 3:
if (aktuell - tonBeginn > tonDauer ) {
tonBeginn = aktuell;
tone( Lautsprecher, noten2[notenNr] );
tonDauer = dauer2[notenNr];
notenNr++;
if ( notenNr == 15 )
notenNr = 0;
}
break;
case 4:
noTone(11);
break;
}
}
Anzeige(score1);
delay(3);
digitalWrite(Anzeige2, LOW);
digitalWrite(Anzeige1, HIGH);
Anzeige(score2);
delay(3);
digitalWrite(Anzeige2, HIGH);
digitalWrite(Anzeige1, LOW);
}
void receiveEvent(int howMany) {
int score1 = Wire.read();
int score2 = Wire.read();
Serial.println(score1);
Serial.println(score2);
}
void Anzeige(int Ziffer) {
digitalWrite(Elemente[0], Status_a[Ziffer]);
digitalWrite(Elemente[1], Status_b[Ziffer]);
digitalWrite(Elemente[2], Status_c[Ziffer]);
digitalWrite(Elemente[3], Status_d[Ziffer]);
digitalWrite(Elemente[4], Status_e[Ziffer]);
digitalWrite(Elemente[5], Status_f[Ziffer]);
digitalWrite(Elemente[6], Status_g[Ziffer]);
}
Vielen Dank für eure Hilfe,
Timrich