Hi,
ich habe folgendes LCD(%product-title% kaufen).
Mein Problem: Immer wenn ich versuche einen Ton mit einer speziellen Funktion auszugeben, funktioniert das LCD nicht mehr. Dies passiert immer wenn ich im Code die Zeile
melody[thisNote]; irgendwo benutze.
Hat jemand eine Idee, woran es liegen könnte?
Hier mein vollständiger Code:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "pitches.h"
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define NUMFLAKES 10 // Number of snowflakes in the animation example
#define LOGO_HEIGHT 42
#define LOGO_WIDTH 50
static const unsigned char PROGMEM logo_bmp[]= {
0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0xe,0x0,0x0,0x0,
0x0,0x0,0x0,0x3,0xc0,0x0,0x0,
0x0,0x0,0x0,0x1,0xe0,0x0,0x0,
0x0,0x0,0x0,0x0,0xf8,0x0,0x0,
0x0,0x0,0x0,0x0,0x7c,0x0,0x0,
0x0,0x0,0x0,0xe0,0x3e,0x0,0x0,
0x0,0x0,0x1f,0xf0,0x1f,0x0,0x0,
0x0,0x0,0x3f,0xf0,0xf,0x80,0x0,
0x0,0x0,0x7f,0xe0,0xf,0x80,0x0,
0x0,0x0,0xff,0xc0,0x7,0xc0,0x0,
0x0,0x1,0xff,0x80,0x7,0xe0,0x0,
0x0,0x3,0xff,0x0,0x7,0xe0,0x0,
0x0,0x7,0xff,0x80,0x3,0xe0,0x0,
0x0,0xf,0xff,0xc0,0x3,0xf0,0x0,
0x0,0xf,0xff,0xe0,0x3,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E_B4, NOTE_AX, NOTE_B4, NOTE_E4, NOTE_E4,
NOTE_AX, NOTE_G4, NOTE_F4, NOTE_G4, NOTE_C4, NOTE_C4,
NOTE_C5, NOTE_B4, NOTE_AX, NOTE_G4, NOTE_B4, NOTE_C5, NOTE_D5,
NOTE_E5, NOTE_D5, NOTE_C5, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_G4, NOTE_G4, NOTE_B4, NOTE_C5, NOTE_D5,
NOTE_C5, NOTE_B4, NOTE_AX, NOTE_G4, NOTE_AX, NOTE_B4, NOTE_E4, NOTE_E4, NOTE_G4, NOTE_AX, NOTE_B4,
NOTE_C5, NOTE_AX, NOTE_B4, NOTE_C5, NOTE_AX, NOTE_B4, NOTE_C5, NOTE_AX, NOTE_C5, NOTE_F5,
NOTE_F5, NOTE_E5, NOTE_D5, NOTE_C5, NOTE_D5, NOTE_E5, NOTE_C5, NOTE_C5,
NOTE_D5, NOTE_C5, NOTE_B4, NOTE_AX, NOTE_B4, NOTE_C5, NOTE_AX, NOTE_AX,
NOTE_C5, NOTE_B4, NOTE_AX, NOTE_G4, NOTE_C4, NOTE_G4, NOTE_AX, NOTE_B4, NOTE_C5
};
int noteDurations[] = {
8, 4, 6, 16, 4, 8, 8,
4, 6, 16, 4, 8, 8,
4, 8, 8, 4, 8, 8, 4, 8, 8, 2,
4, 6, 16, 4, 8, 8,
4, 6, 16, 4, 8, 8,
4, 6, 16, 4, 6, 16,
4, 6, 16, 8, 8, 8, 8,
2, 8, 8, 8, 8, 3, 8, 8, 8, 8, 8,
2, 8, 8, 8, 8, 3, 8, 8, 8, 8, 8,
4, 6, 16, 4, 6, 16, 4, 8, 8, 2,
2, 8, 8, 8, 8, 3, 8, 2,
2, 8, 8, 8, 8, 3, 8, 2,
4, 6, 16, 4, 4, 2, 4, 4, 1
};
void setup() {
Serial.begin(9600);
pinMode(speakerPin, OUTPUT);
pinMode(8,OUTPUT);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println("trying 2 get this thing 2 work");
}
display.display();
display.clearDisplay();
testdrawbitmap();
display.invertDisplay(true);
delay(1000);
display.invertDisplay(false);
delay(1000);
}
void loop() {
for(int thisNote = 0; thisNote < sizeof(melody) / 2;thisNote++) {
int noteDuration = 2000 / noteDurations[thisNote];
tone(2,melody[thisNote],noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(buzzerPin);
}
}
void testdrawbitmap(void) {
display.clearDisplay();
display.drawBitmap(
(display.width() - LOGO_WIDTH ) / 2,
(display.height() - LOGO_HEIGHT) / 2,
logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, 1);
display.display();
delay(1000);
}
#define XPOS 0 // Indexes into the 'icons' array in function below
#define YPOS 1
#define DELTAY 2
void testanimate(const uint8_t *bitmap, uint8_t w, uint8_t h) {
int8_t f, icons[NUMFLAKES][3];
for(f=0; f< NUMFLAKES; f++) {
icons[f][XPOS] = random(1 - LOGO_WIDTH/2, display.width());
icons[f][YPOS] = -LOGO_HEIGHT/2;
icons[f][DELTAY] = random(1, 6);
Serial.print(F("x: "));
Serial.print(icons[f][XPOS], DEC);
Serial.print(F(" y: "));
Serial.print(icons[f][YPOS], DEC);
Serial.print(F(" dy: "));
Serial.println(icons[f][DELTAY], DEC);
}
for(;;) { // Loop forever...
display.clearDisplay(); // Clear the display buffer
// Draw each snowflake:
for(f=0; f< NUMFLAKES; f++) {
display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, WHITE);
}
display.display(); // Show the display buffer on the screen
delay(200); // Pause for 1/10 second
// Then update coordinates of each flake...
for(f=0; f< NUMFLAKES; f++) {
icons[f][YPOS] += icons[f][DELTAY];
// If snowflake is off the bottom of the screen...
if (icons[f][YPOS] >= display.height()) {
// Reinitialize to a random position, just off the top
icons[f][XPOS] = random(1 - LOGO_WIDTH/2, display.width());
icons[f][YPOS] = -LOGO_HEIGHT;
icons[f][DELTAY] = random(1, 6);
}
}
}
}