Great questions. Although my main question is not for help with writing/uploading code or hooking up the buzzer, it is whether anyone knows or has seen a buzzer work with a T88 Tiny or has used a library that works with it. However, to answer your questions, if it helps, I believe it is an active buzzer. I got it from an old Arduino Uno kit, and it works perfectly when connected to an Arduino Uno, so I am assuming the problem is the T88 tiny. I have gone back and forth from the Uno to the Tiny to make sure I didn't break it, and it worked on the Uno every time.
In my initial question, I did point out that I was able to upload code to the ATtiny88 ( I used the unplug, upload wait, then insert plug method and got 100% complete prompt) to blink RGB LEDs and even control them with a button, which worked on the T88. I also had code that used blinking RGB LEDs, a button to switch between light colors, and Rtttl that uploaded successfully. With that code, if I had RTTTL playing in a case, it wouldn't let me switch to the next case till the Rtttl song was finished by design, so when uploaded to the Uno, even if I pressed the button, the next case would not activate until the music was finished playing. When put on the T88, I could switch between cases, but for about as long as the music usually lasted on the Uno I could not switch to the next case when pressing the button with the T88, even though nothing was playing through the buzzer. That told me the T88 is trying to read through rtttl code, but no sound happens. It also tells me the code is working as it should, and the pins I was connected to were right. Although with that code having variables of LED signals or libraries interfering with each other, I switched to the simpler code I posted to keep troubleshooting different libraries, and still no sound. I also tried probing other pins with the input pin that led to the buzzer and heard nothing, just in case the pins were mapped wrong.
I have tried a TinyRTTTL Library, but still no sound; maybe I can try the one you sent to see if some squeaks can get through. Here is my button and blink code with a schematic, but I am looking for the answer of if it is possible.
#include <PlayRtttl.hpp>
const int buttonPin = 2; // Pin connected to the push button
int settingMode = 0; // Counter for settings
int buttonState = HIGH; // Current state of the button
int lastButtonState = HIGH; // Previous state of the button
int redVal;
int blueVal;
int greenVal;
int LED2_redVal;
int LED2_blueVal;
int LED2_greenVal;
const int BUZZER_PIN = 5;
#define BLUE 6
#define GREEN 8
#define RED 9
#define LED2_BLUE 10
#define LED2_GREEN 11
#define LED2_RED 12
#define delayTime 20
bool played = false;
const char mission_imp[] PROGMEM = "MissionImp:d=16,o=4,b=95:32d,32z,32d,32z,32f,32z,32g,32z,32d,32z,32d,32z,32c,32z,32c#,32z";
const char Ama_Grace [] PROGMEM = "Amazing Grace:o=5,d=16,b=80,b=80:8c,2f,a,g,f,2a,8a,8g,2f,4d,2c,8c,2f,a,g,f,2a,8g,8a,2c6.";
const char Popeye [] PROGMEM = "Popeye:o=5,d=8,b=160,b=160:a5,c,c,c,4a#5,a5,4c,2p,c,d,a#5,d,4f,d,2c,p,c,d,a#5,d,f,e,d,c,d,c,a5,f5,a5,c,d,c,4a#5,g5,2f5";
const char WeAreThe [] PROGMEM = "WeAreThe:d=16,o=4,b=63:2d5,8c#5,8d5,4c#5,4a,8f#,4b,2f#,8a,2d5,8e5,8f#5,4a5,4f#5,b,2b,4b,4a,8b,4a,4g,4g5,4f#5,8g5,4f#5,4e5,4f#5,4d5,8g5,4f#5,4d5,8g5,4f5,4d5,8g5,4f5,2d5,8c5,8a,2d5";
const char WeAreThe1 [] PROGMEM = "WeAreThe1:d=4,o=5,b=100:2f,8e,8f,e,c,8p,8a4,d,a.4,2p,8c,2f,8g,8a,c6,a.,8d.,8e,2c,2p,d.,c,8d,c.,a#4,8p,a#.,a,8a#,a.,g,8p,a.,f,8a#,a.,8f,8p,8a#,g#.,f.,8a#,g#.,f.,2p";
const char WeAreThe2 [] PROGMEM = "WeAreThe2:d=4,o=5,b=80:2d,8c#,8d,c#,a4,8f#4,b4,2f#4,8a4,2d,8e,8f#,a,f#,8d,2b4,b4,a4,8b4,a4,g4,g4,f#,8g,f#,e,f#,d,8g,f#,d,8g,f,d,8g,f,2d";
const char Dead [] PROGMEM = "DeathMus:d=16,o=4,b=100:b,f5,p,f5,f5,f.5,e.5,d5,c5,g,p,e,c";
//America:d=16,o=5,b=200:4g,p,4e,4c,8p,p,4e,4p,4g,4p,4c6,2p,4p,4e6,p,4d6,4c6,4p,4e,4p,4f#,4p,2g,2p,4g,4p,2e6,4p,4d6,4c6,4p,2b,2p,4a,p,4b,4c6,4p,4e,4p,4f#,4p,4g,8p,p
//StarWars:d=4,o=5,b=112:8g,16p,8g,16p,8g,16p,16d#.,32p,32a#.,8g,16p,16d#.,32p,32a#.,g,8p,32p,8d6,16p,8d6,16p,8d6,16p,16d#.6,32p,32a#.,8f#,16p,16d#.,32p,32a#.,g,8p,32p,8g6,16p,16g.,32p,32g.,8g6,16p,16f#.6,32p,32f.6,32e.6,32d#.6,16e6,8p,16g#,32p,8c#6,16p,16c.6,32p,32b.,32a#.,32a.,16a#,8p,16d#,32p,8f#,16p,16d#.,32p,32g.,8a#,16p,16g.,32p,32a#.,d6,8p,32p,8g6,16p,16g.,32p,32g.,8g6,16p,16f#.6,32p,32f.6,32e.6,32d#.6,16e6,8p,16g#,32p,8c#6,16p,16c.6,32p,32b.,32a#.,32a.,16a#,8p,16d#,32p,8f#,16p,16d#.,32p,32g.,8g,16p,16d#.,32p,32a#.,g
//HarryPot:d=16,o=4,b=125:2p,8p,8b,8e.4,g4,8f#4,4e4,8b4,4a.4,4f#.4,8e.4,g4,8f#4,4d4,8f4,2e4,8p,8b,8e.4,g4,8f#4,4e4,8b4,4d5,8c#5,4c5,8g#4,8c.5,b4,8a#4,4f#4,8g4,2e4,8p,8g4,4b4,8g4,4b4,8g4,4c5,8b4,4a#4,8f#4,8g.4,b4,8a#4,4a#,8b,2b4,8p
void setup() {
// Use internal pull-up resistor (Button connects pin to GND)
pinMode(buttonPin, INPUT_PULLUP);
Serial.begin(9600);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
pinMode(RED, OUTPUT);
pinMode(LED2_GREEN, OUTPUT);
pinMode(LED2_BLUE, OUTPUT);
pinMode(LED2_RED, OUTPUT);
digitalWrite(GREEN, LOW);
digitalWrite(BLUE, LOW);
digitalWrite(RED, LOW);
digitalWrite(LED2_GREEN, LOW);
digitalWrite(LED2_BLUE, LOW);
digitalWrite(LED2_RED, LOW);
}
void loop() {
// Read the current state of the button
buttonState = digitalRead(buttonPin);
// Check if button state changed from HIGH to LOW (a press)
if (buttonState != lastButtonState) {
if (buttonState == LOW) {
settingMode++; // Move to next setting
// Reset to setting 0 after reaching the limit (e.g., 5 settings)
if (settingMode > 4) {
settingMode = 0;
}
Serial.print("Current Mode: ");
Serial.println(settingMode);
}
// Small delay to debounce the mechanical button
delay(50);
}
// Save current state for next loop iteration
lastButtonState = buttonState;
// Execute different code for each setting
switch (settingMode) {
case 0:
played = false;
// Code for Setting 1 (e.g., All white with music)
int redVal = 255;
int blueVal = 255;
int greenVal = 255;
int LED2_redVal = 255;
int LED2_blueVal = 255;
int LED2_greenVal = 255;
analogWrite( GREEN, greenVal );
analogWrite( RED, redVal );
analogWrite( BLUE, blueVal );
analogWrite( LED2_GREEN, LED2_greenVal );
analogWrite( LED2_RED, LED2_redVal );
analogWrite( LED2_BLUE, LED2_blueVal );
playRtttlBlockingPGM(BUZZER_PIN, mission_imp);
delay(500);
playRtttlBlockingPGM(BUZZER_PIN, Ama_Grace);
delay(500);
playRtttlBlockingPGM(BUZZER_PIN, Popeye);
delay(500);
playRtttlBlockingPGM(BUZZER_PIN, WeAreThe);
delay(500);
playRtttlBlockingPGM(BUZZER_PIN, WeAreThe1);
delay(500);
playRtttlBlockingPGM(BUZZER_PIN, WeAreThe2);
delay(500);
break;
case 1:
// Code for Setting 1 (e.g., All Fade)
redVal = 255;
blueVal = 0;
greenVal = 255;
LED2_redVal = 255;
LED2_blueVal = 0;
LED2_greenVal = 255;
analogWrite( GREEN, greenVal );
analogWrite( RED, redVal );
analogWrite( BLUE, blueVal );
analogWrite( LED2_GREEN, LED2_greenVal );
analogWrite( LED2_RED, LED2_redVal );
analogWrite( LED2_BLUE, LED2_blueVal );
break;
case 2:
// Code for Setting 2 (e.g., LED Fade)
redVal = 255;
blueVal = 0;
greenVal = 0;
LED2_redVal = 255;
LED2_blueVal = 0;
LED2_greenVal = 0;
for( int i = 0 ; i < 255 ; i += 1 ){
greenVal += 1;
redVal -= 1;
LED2_greenVal += 1;
LED2_redVal -= 1;
analogWrite( GREEN, greenVal );
analogWrite( RED, redVal );
analogWrite( BLUE, blueVal );
analogWrite( LED2_GREEN, LED2_greenVal );
analogWrite( LED2_RED, LED2_redVal );
analogWrite( LED2_BLUE, LED2_blueVal );
delay( delayTime );
}
redVal = 0;
blueVal = 0;
greenVal = 255;
LED2_redVal = 0;
LED2_blueVal = 0;
LED2_greenVal = 255;
for( int i = 0 ; i < 255 ; i += 1 ){
blueVal += 1;
greenVal -= 1;
LED2_greenVal -= 1;
LED2_blueVal += 1;
analogWrite( BLUE, blueVal );
analogWrite( GREEN, greenVal );
analogWrite( RED, redVal );
analogWrite( LED2_GREEN, LED2_greenVal );
analogWrite( LED2_RED, LED2_redVal );
analogWrite( LED2_BLUE, LED2_blueVal );
delay( delayTime );
}
redVal = 0;
blueVal = 255;
greenVal = 0;
LED2_redVal = 0;
LED2_blueVal = 255;
LED2_greenVal = 0;
for( int i = 0 ; i < 255 ; i += 1 ){
redVal += 1;
blueVal -= 1;
LED2_redVal += 1;
LED2_blueVal -= 1;
analogWrite( RED, redVal );
analogWrite( BLUE, blueVal );
analogWrite( GREEN, greenVal );
analogWrite( LED2_GREEN, LED2_greenVal );
analogWrite( LED2_RED, LED2_redVal );
analogWrite( LED2_BLUE, LED2_blueVal );
delay( delayTime );
}
break;
case 3:
redVal = 0;
blueVal = 0;
greenVal = 0;
LED2_redVal = 0;
LED2_blueVal = 0;
LED2_greenVal = 0;
for( int i = 0 ; i < 255 ; i += 1 ){
redVal += 1;
blueVal += 1;
greenVal += 1;
LED2_greenVal += 1;
LED2_blueVal += 1;
LED2_redVal += 1;
analogWrite( RED, redVal );
analogWrite( BLUE, blueVal );
analogWrite( GREEN, greenVal );
analogWrite( LED2_GREEN, LED2_greenVal );
analogWrite( LED2_RED, LED2_redVal );
analogWrite( LED2_BLUE, LED2_blueVal );
delay( delayTime );
}
redVal = 255;
blueVal = 255;
greenVal = 255;
LED2_redVal = 255;
LED2_blueVal = 255;
LED2_greenVal = 255;
for( int i = 0 ; i < 255 ; i += 1 ){
redVal -= 1;
blueVal -= 1;
greenVal -= 1;
LED2_greenVal -= 1;
LED2_blueVal -= 1;
LED2_redVal -= 1;
analogWrite( RED, redVal );
analogWrite( BLUE, blueVal );
analogWrite( GREEN, greenVal );
analogWrite( LED2_GREEN, LED2_greenVal );
analogWrite( LED2_RED, LED2_redVal );
analogWrite( LED2_BLUE, LED2_blueVal );
delay( delayTime );
}
break;
case 4:
// Code for Setting 3 (e.g., LED Solid blue)
redVal = 0;
blueVal = 255;
greenVal = 0;
LED2_redVal = 0;
LED2_blueVal = 255;
LED2_greenVal = 0;
analogWrite( GREEN, greenVal );
analogWrite( RED, redVal );
analogWrite( BLUE, blueVal );
analogWrite( LED2_GREEN, LED2_greenVal );
analogWrite( LED2_RED, LED2_redVal );
analogWrite( LED2_BLUE, LED2_blueVal );
break;
case 5:
// Code for Setting 3 (e.g., LED Solid red)
redVal = 255;
blueVal = 0;
greenVal = 0;
LED2_redVal = 255;
LED2_blueVal = 0;
LED2_greenVal = 0;
analogWrite( GREEN, greenVal );
analogWrite( RED, redVal );
analogWrite( BLUE, blueVal );
analogWrite( LED2_GREEN, LED2_greenVal );
analogWrite( LED2_RED, LED2_redVal );
analogWrite( LED2_BLUE, LED2_blueVal );
break;
case 6:
// Code for Setting 3 (e.g., LED Solid red)
redVal = 0;
blueVal = 0;
greenVal = 0;
LED2_redVal = 0;
LED2_blueVal = 0;
LED2_greenVal = 0;
analogWrite( GREEN, greenVal );
analogWrite( RED, redVal );
analogWrite( BLUE, blueVal );
analogWrite( LED2_GREEN, LED2_greenVal );
analogWrite( LED2_RED, LED2_redVal );
analogWrite( LED2_BLUE, LED2_blueVal );
if(!played){
playRtttlBlockingPGM(BUZZER_PIN, Dead);
played = true;
}
break;
}
}