Im making a very (very) simple program for testing purposes.
With a multimeter i tested all output ports and all goed correctly! Also, the blink usb example worked great
Now, im trying to make the following: a battery tester!
Currently i have around 200 batteries in a box and i want to check if they are providing roughly 1 V or not. (as a test) (skip the fact that i have a multimeter, its the idea that counts)
So i connected a wire to ground on the digispark and a wire to the P2 of the digispark, and fired it up with the code below. However, the red light starts to blink arbitrarily
even when i dont connect the two wires to anything. If i connect the P2 wire to GND the red light stays off as it should. Digispark is connected to usb port of PC by the way.
Connecting one wire to PLUS of full battery and the other one to MIN does not give me any feedback, arbitrary blinking continues.
int sensorvalue = 0;
int eightbitsensorvalue=0;
void setup() {
//All pins are capable of Digital output, though P5 is 3 V at HIGH instead of 5 V
pinMode(0, OUTPUT);
pinMode(2, INPUT);
}
void loop() {
sensorvalue = analogRead(1); //reads in from pin 2
eightbitsensorvalue = map(sensorvalue, 0, 1023, 0, 255);
if (eightbitsensorvalue>50) //should be roughly 1/5th of 5V is 1 V
{
digitalWrite(0,HIGH);
}
else
{
digitalWrite(0,LOW);
}
}