<p> LISTING PROGRAM</p><p>// include the library code: #include <LiquidCrystal.h></p><p>#define charging A0 #define discharge A1 const int numReadings = 20; int readings[numReadings]; // the readings from the analog input int readIndex = 0; // the index of the current reading int total = 0; // the running total int average = 0; // the average</p><p>// initialize the library with the numbers of the interface pins LiquidCrystal lcd(7, 6, 5, 4, 3, 2); void setup() { // set up the LCD's number of columns and rows: lcd.begin(16, 2); Serial.begin(9600);</p><p> for (int thisReading = 0; thisReading < numReadings; thisReading++) readings[thisReading] = 0; } void loop() { int a = analogRead(charging);</p><p>// subtract the last reading: total = total - readings[readIndex]; // read from the sensor: readings[readIndex] = analogRead(discharge); // add the reading to the total: total = total + readings[readIndex]; // advance to the next position in the array: readIndex = readIndex + 1;</p><p>// if we're at the end of the array... if (readIndex >= numReadings) { // ...wrap around to the beginning: readIndex = 0; }</p><p>// calculate the average: average = total / numReadings; // send it to the computer as ASCII digits Serial.println(average);</p><p> delay(1); // delay in between reads for stability</p><p>1 2</p><p> int tegangan = average * 4.88;</p><p>Serial.print("Tegangan Baterai terbaca = "); Serial.print(tegangan); Serial.println("mV "); Serial.println(); Serial.println(); Serial.println();</p><p>// 1 cacahan = 0.0048 // 3 volt = 625 cacahan // 4.2 volt = 875 cacahan // rumus (875 - 625) * 0.4 = 100%</p><p>// Overcharging & surge protection 4.1 volt = 854 cacahan // rumus (854-625) * 0.43 = 100%</p><p> int keluar = (average - 625)*0.43;</p><p> if (a >= 204) { lcd.setCursor(3, 0); lcd.print("POWERBANK"); lcd.setCursor(0, 1); lcd.print("Charging= "); lcd.print(keluar); lcd.print("% "); delay(2000);</p><p> lcd.setCursor(0, 1); lcd.print("Teg Batt= "); lcd.print(tegangan); lcd.print("mV"); delay(2000); }</p><p> else { lcd.setCursor(3, 0); lcd.print("POWERBANK"); lcd.setCursor(0, 1); lcd.print("Discharge= "); lcd.print(keluar); lcd.print("% "); delay(2000);</p><p> lcd.setCursor(0, 1); lcd.print("Teg Batt= "); lcd.print(tegangan); lcd.print("mV"); delay(2000); }</p><p> delay(500); lcd.clear();</p><p>}</p><p>2</p>
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages2 Page
-
File Size-