The fett263 prop has a number of do-a-gesture-to-turn-saber-on features.
Are any of these on?
Does the serial monitor say anything interesting when this happens?
i didn’t have the serial monitor up at the time. going forward i’ll have it up and check what gets logged. I’ve tested a bunch of times since my last post and it’s not happening now, it’s very random. Is that saber_fett263_button.h
file the only one that has the turn on events? Or are there other files i need to look through?
I’m not sure if you are asking becasue you want these features or if you’re asking because you want to avoid these features, but it looks like the Fett263, BC, Sabersense and SA22C props have some sort of turn-on-with-gesture features.
Sorry, I was asking so i can find all instances of ignition events and wrap them in that condition, or is there a better way of doing that? Simpler? A way to block ignition.
The good news (i think) is that it happened again and this time i had the monitor running. Here is what was logged after ignition
saber is off //inside the saberOff function
unit = 1 vol = 0.50, Playing Kenobi/in/in1.wav
channels: 1 rate: 44100 bits: 16
Saber is OFF: Retracting blade. //motor is running to retract the blade
EVENT: Power-Released#1 millis=144683
EVENT: Power-Released millis=144683
EVENT: Clash millis=144925
EVENT: Stab millis=145046
Ignition.
I added two comments in that log to show you that the program is retracting the blade and the motor is running however those events seem to cause the saber to turn back on which cause the motor to turn the opposite way and extend the balde. Do clash and stab events events ignite the saber if off?
You could try using a simpler prop file, like saber.h
The Fett263 has a STAB_ON feature, so it could cause it to turn on.
I recommend reading the top of the prop file to find all the various *_ON features.
Thanks! i was able to get it working correctly.
Is there a battery level function i can call in the loop that will give me the voltage reading of my battery? I see it in the serial monitor however im having problem locating the function. I tried looking in the forum but no luck. My plan is if the level gets to a certain point like 10v, i’ll have my blade blink.
also, i went with controlling my blade using the external MOSFET module, so im using ditigalWrite HIGH and LOW.
I found this function but its returning 4.5v.
float battery_voltage = battery_monitor.battery();
However, im struggling to figure out how to scale it to read a 12v lipo battery which what im using to power the device. I do have a step down converter for the proffie board 12v - 5v.
Any idea on how i can solve this?
First of all, there is a style for this:
So you can write a style like:
StylePtr<Mix<IfLessThan<BatteryLevel, 3276>, BLINKING_STYLE_HERE, NORMAL_STYLE_HERE>>()
However battery_monitor.battery() and BatteryLevel both measure the voltage the board receives on the BATT+ input, which cannot be higher than 5.5 volts. (Or the board will die.)
However, there are ways… you can use a voltage divider.
Basically, what you need is two resistors, something like a 47k and a 10k. Hook up the 47k to + on the battery, hook up the 10k to - on the battery (or gnd on the board, same thing) and hookup the two resistors together. Then feed the middle point between the resistors to an analog-capable pin on the board.
Now, you can get the voltage by doing:
float V = anlogRead(pin) * 3.3/1024;
float I = V / 10000;
float battery_voltage = I * (10000 + 47000);
Then, if you like, you can modify the battery.h file to just do this for you, and then it will work with BatteryLevel as well.
Thanks, i’ll try doing that with the resistors.
I have RX and TX free, can i use one of them? I see from the chart that they are both ADC capable pins
Yes, you can use either of those.
Ok, thanks.
So instead of having the blade blink, i was thinking of playing a sound from the sound fonts. Is that possible? I have a batteryMonitor function i wrote to monitor the 12v battery on pin 16. however im having an issue playing the wav. Here is what i have:
void batteryLevelMonitor() {
static unsigned long lastBatteryCheck = 0;
if (motor_running) return; // Avoid misreadings due to motor load
if (millis() - lastBatteryCheck > 5000) { // Check battery every 5 seconds
lastBatteryCheck = millis();
lipo_battery_voltage = getBatteryVoltage(); // Read battery voltage safely
if (lipo_battery_voltage < 3.0) return; // Ignore invalid readings
Serial.print("Battery Voltage: ");
Serial.print(lipo_battery_voltage);
Serial.println("V");
//Play low battery warning sound if voltage is below 10.8V
if (lipo_battery_voltage <= 10.8 && !lowBatterySoundPlayed) {
SoundFont::Play("proffie/lowbatt/lowbatt.wav"); // Play custom sound
lowBatterySoundPlayed = true; // Ensure it only plays once
}
// Reset the flag if the battery is recharged above 11V
if (lipo_battery_voltage > 11.0) {
lowBatterySoundPlayed = false;
}
}
}
Im getting an error here
SoundFont::Play("proffie/lowbatt/lowbatt.wav");
error:
error: 'SoundFont' has not been declared
1751 | SoundFont::Play("proffie/lowbatt/lowbatt.wav"); // Play custom sound
whats the correct way to play a sound font in the loop?
Try SaberBase::DoLowBatt();
Also, I think you want to declare this as an int
static unsigned long lastBatteryCheck = 0;
If it’s static, you can’t change it later with lastBatteryCheck = millis();
Yes you can. I think you’re mixing up static
and const
.
Thank you! This is what i needed!. In case you or anyone else wants the function, here it is
void batteryLevelMonitor() {
static unsigned long lastBatteryCheck = 0;
static unsigned long lastLowBattSoundTime = 0;
static bool lowBatterySoundPlayed = false;
const unsigned long lowBattSoundInterval = 10000; // Play warning every 10 seconds
if (motor_running) return; // Avoid misreadings due to motor load
if (millis() - lastBatteryCheck > 5000) { // Check battery every 5seconds
lastBatteryCheck = millis();
// Read the battery voltage
int rawADC = analogRead(batteryPin);
float V = rawADC * (3.3 / 1024.0);
float lipo_battery_voltage = V * ((R1 + R2) / R2) * correction_factor;
Serial.print("Battery Voltage: ");
Serial.print(lipo_battery_voltage);
Serial.println("V");
// If battery is low, play warning sound periodically (every 10 seconds)
if (lipo_battery_voltage <= lowerBatteryTolerance) {
if (millis() - lastLowBattSoundTime >= lowBattSoundInterval) {
Serial.println("Playing low battery sound...");
SaberBase::DoLowBatt();
lastLowBattSoundTime = millis();
}
}
// Reset flag if battery recovers above 11.0V
if (lipo_battery_voltage > 11.0) {
lastLowBattSoundTime = 0;
}
}
}
I do wonder, is there a way to play a font sound by manually playing it?
Regular analogRead will slow down ProffieOS a bit, I recommend using the AnlogReader class instead:
It’s a little more complicated to use, but it avoids busy-waiting for the reader circuitry.
hybrid_font.PlayCommon(&SFX_font)
Oops. Yup, ignore me.
Thanks! Ill look into this.