43 lines
848 B
C++
43 lines
848 B
C++
int sensor = A0;
|
|
int LED = 13;
|
|
int light;
|
|
unsigned int battery = 0;
|
|
unsigned int capacity = 50000;
|
|
unsigned int ticks = 0;
|
|
unsigned int wait = 100;
|
|
double percentage;
|
|
|
|
void setup() {
|
|
// put your setup code here, to run once:
|
|
pinMode(LED,OUTPUT);
|
|
Serial.begin(9600);
|
|
}
|
|
|
|
void PrintBatteryPercentage() {
|
|
Serial.print(ticks);
|
|
Serial.print("ms, charge at ");
|
|
percentage = 100 * ((double)battery / (double)capacity);
|
|
Serial.print(percentage);
|
|
Serial.println("%");
|
|
}
|
|
|
|
void loop() {
|
|
// put your main code here, to run repeatedly:
|
|
light = analogRead(sensor);
|
|
battery += light;
|
|
ticks += wait;
|
|
|
|
if (battery >= capacity) {
|
|
battery = capacity;
|
|
Serial.print(ticks);
|
|
Serial.print("ms ");
|
|
Serial.println("FULLY CHARGED");
|
|
ticks = 0;
|
|
delay(20000);
|
|
} else {
|
|
PrintBatteryPercentage();
|
|
}
|
|
|
|
delay(wait);
|
|
}
|