Étape 5: Le programme
/*
Testeur de pile solaire 15V-1 a
par Mike Soniat
8 septembre 2012
*/
const int RxPin = 3 ;
#include < SoftwareSerial.h >
SoftwareSerial lcdPanel = SoftwareSerial (255, RxPin) ;
int voltPin = 1 ;
int ampPin = 2 ;
int readVolts = 0 ;
int readAmps = 0 ;
int maxVolts = 15 ; Doit correspondre des résistances du circuit tension
float voltageFactor = 0 ;
flotteur de tension = 0 ;
flotteur courant = 0 ;
flotteur électrique = 0 ;
const int clearIt = 12 ;
const int cr = 13 ;
const int backLightOn = 17 ;
const int backLightOff = 18 ;
void setup() {}
pinMode (RxPin, sortie) ;
digitalWrite (RxPin, élevé) ;
lcdPanel.begin(9600) ;
startUp() ;
}
void loop()
{
mesurer la tension
readVolts = analogRead(voltPin) ;
Si (readVolts > 0)
{
while (readVolts > 0)
{
readVolts = analogRead(voltPin) ;
Si (readVolts > 0)
{
voltageFactor = 1024 / maxVolts ;
tension = readVolts / voltageFactor ;
clearLCD() ;
lcdPanel.print ("Reading") ;
lcdPanel.print(voltage) ;
lcdPanel.print("V") ;
lcdPanel.write(cr) ;
lcdPanel.print (« basculer le commutateur à A") ;
}
Delay(1000) ;
}
}
d’autre
{
startUp() ;
}
Basculez vers le circuit de courant
readAmps = analogRead(ampPin) ;
while (readAmps > 0)
{
Si (tension > 0)
{
readAmps = analogRead(ampPin) ;
courant = readAmps ;
puissance = tension * actuel ;
clearLCD() ;
lcdPanel.print(voltage) ;
lcdPanel.print (« V ») ;
lcdPanel.print ("J’ai =") ;
lcdPanel.print(current) ;
lcdPanel.print("mA") ;
lcdPanel.write(cr) ;
lcdPanel.print(power) ;
lcdPanel.print("mW") ;
Delay(1000) ;
}
else {}
readAmps = analogRead(ampPin) ;
}
}
Delay(1000) ;
}
Sub clearLCD()
{
lcdPanel.write(clearIt) ; Claire
Delay(5) ;
}
Sub startUp()
{
clearLCD() ;
lcdPanel.write(backLightOn) ;
lcdPanel.print ("15V - 1 a solaire") ;
lcdPanel.write(cr) ;
lcdPanel.print ("testeur de cellules") ;
Delay(3000) ;
clearLCD() ;
lcdPanel.print (« basculer le commutateur sur V ») ;
lcdPanel.print ("et cellule de se connecter") ;
Delay(2000) ;
}