Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* Day 0 - AI Apocalypse by inventr.io
* Learn more at https://inventr.io/PLACEHOLDER
* Learn more at https://inventr.io/PLACEHOLDER **don't forget to fix me!
*
* Building a battery charging controller.
* Building a battery charging controller with an added aduible LOW BATTERY warning.
*
* We have batteries to store the power generated by our solar panels, but the charging
* was handled by the building AI, which has been disabled.
Expand All @@ -14,8 +14,11 @@
* A photoresistor is a light-sensitive component that changes resistance based on the
* amount of light it receives. When light increases, the resistance decreases.
*
* A passive buzzer is a simple audio device that can generate different tones or melodies.
* and uses the tone() function to produce the desired frequency and control the sound output.
*
* Since we'll be powering our lights from the batteries we'll be adding on to our
* previous switched light circuit and code.
* previous charging batteries circuit and code.
*
* Alex Eschenauer
* David Schmidt
Expand Down Expand Up @@ -56,9 +59,10 @@ const uint8_t ALARM_PIN = 24; // Active buzzer simulating our alarm speaker
const uint8_t CHARGING_RATE = A8; // Photoresistor input simulating battery charge rate

/*
* NOTE: While HIGH/LOW now make more sense when using a pull-down resistor, it still
* makes even MORE clear using PRESSED / NOT_PRESSED. However, now we set
* PRESSED equal to HIGH. We can also use ON / OFF for our lights.
* NOTE: Using a pull-up resistor can cause some confusion because the input pin connected
* to our button will read HIGH when the button is NOT pressed, and LOW when the
* button IS pressed. We can reduce this confusion a little by defining a
* new constant for the state of our button: "PRESSED"
*/
const uint8_t PRESSED = LOW; // Button input pin reads LOW when pressed
const uint8_t NOT_PRESSED = HIGH; // Button input pin reads HIGH when NOT pressed
Expand Down Expand Up @@ -223,16 +227,21 @@ void loop() {
// Save current charge level for next tinme through loop()
previous_charge_percentage = battery_charge_percentage;

// Output the numbers we wish to plot using the Serial Plotter. The first two numbers
// are just to show the 0% and 100% charged points so the plotter won't continuously
// change the scale.
Serial.print(0); // show line in plotter for 0% charge
// Output the numbers we wish to plot using the Serial Plotter.
// The first two numbers are just to show the 0% and 100% charged points
// so the plotter won't continuously change the scale.
// Plot labels must preceed their variable, be enclosed in quotes, end with a colon, contain no spaces
Serial.print("0%:"); // Label for 0% charge
Serial.print(0); // Show line in plotter for 0% charge
Serial.print(", ");
Serial.print(100); // show line in plotter for 100% charge
Serial.print("100%:"); // Label for 100% charge
Serial.print(100); // Show line in plotter for 100% charge
Serial.print(", ");
Serial.print(battery_charge_percentage); // show current battery charge in percent
Serial.print("%-charged:"); // Label for battery_charge_percentage
Serial.print(battery_charge_percentage); // Plot battery_charge_percentage variable
Serial.print(", ");
Serial.println(map(current_charging_rate, 0, 1023, 0, 100)); // show charge rate, in percent
Serial.print("ChargeRate:"); // Label for battery_charge_percentage
Serial.println(map(current_charging_rate, 0, 100, 0, 100)); // Show charge rate in percent & set y-axis scale

// =========== Second part of loop is our prior button / LED control

Expand Down