I am using a programming module for an attiny85 microchip connected to a USB on my laptop. I am using the arduino IDE to program the chip.
My sketch is posted below. I cannot get the low batt warning sequence of 15 blinks at the end to run no matter what I do. All other light behaviors are executing perfectly.
What the heck am I missing???? Please help. Thx
My sketch is posted below. I cannot get the low batt warning sequence of 15 blinks at the end to run no matter what I do. All other light behaviors are executing perfectly.
What the heck am I missing???? Please help. Thx
light fading and blinking:
//8 mghz
// ***MAIN LED AT 91.7% BRIGHTNESS WITH LOW BATT ALERT***
// THIS SKETCH IS THE LATEST FOR THE NEW 2026 PCB WITH THE FORUM TEAM
// THIS SKETCH IS CONFIGURED FOR EASY TESTING (QUICK FADE UP AND DOWN)
// REVISE FADE TIMING WHEN TESTING IS COMPLETE
const int ledPin = 0;
const int sensorPin = 2;
const int alertPin = 1;
const int battPin = 5;
const int darkPin = 3;
int delayTime = 30000;
int sensorValue = LOW;
unsigned long lastmotion;
// ATMEL ATTINY85
//
// +-\/-+
// BATT (D 5) PB5 1| |8 Vcc
// DARK (D 3) PB3 2| |7 PB2 (D 2) SENSOR
// (D 4) PB4 3| |6 PB1 (D 1) ALERT
// GND 4| |5 PB0 (D 0) LED
// +----+
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(sensorPin, INPUT);
pinMode(alertPin, OUTPUT);
pinMode(battPin, INPUT_PULLUP);
pinMode(darkPin, INPUT_PULLUP);
digitalWrite(sensorPin, HIGH);//CHANGE TO LOW AFTER TESTING
digitalWrite(battPin, HIGH); //CHANGE TO LOW AFTER TESTING
digitalWrite(darkPin, HIGH);//CHANGE TO LOW AFTER TESTING
//delay(60000); //UNCOMMENT AFTER TESTING
}
void loop() {
while (digitalRead(darkPin) == HIGH) { //CHANGE TO LOW AFTER TEST
analogWrite(ledPin, 1);
analogWrite(alertPin, 100);
while (digitalRead(sensorPin) == HIGH) {
for (int i = 0; i < 5; i++) {
digitalWrite(ledPin, HIGH); // turn the LED on
delay(500); // wait for 500 milliseconds (half a second)
digitalWrite(ledPin, LOW); // turn the LED off
delay(500); // wait for 500 milliseconds
}
// fade in from min to max 550 mA:
for (int fadeValue = 1 ; fadeValue <= 234; fadeValue += 1) {
// sets the value (range from 2 to 234):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(80); //CHANGE TO 386 AFTER TEST
}
delay(5000);
lastmotion = millis();
while (millis() < lastmotion + delayTime)
if (digitalRead(sensorPin) == LOW) { //CHANGE TO HIGH AFTER TEST
lastmotion = millis();
}
delay(1000); //Keep this fix - 1 unit
// fade out from max to min 40 mA:
for (int fadeValue = 234 ; fadeValue >= 1; fadeValue -= 1) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(40); //CHANGE TO 193 AFTER TEST
}
}
analogWrite(ledPin, 1);
delay(1000);
[B]// NO MATTER WHAT I DO, I CANNOT GET THE CODE BELOW TO RUN AT ALL. IT SIMPLY GETS SKIPPED AND LOOPS BACK TO THE TOP
// WHAT AM I MISSING??
while (digitalRead(battPin) == HIGH) { //CHANGE TO LOW AFTER TEST
for (int i = 0; i < 15; i++) {
digitalWrite(ledPin, HIGH); // turn the LED on
delay(50); // wait for 50 milliseconds (20th of a second)
digitalWrite(ledPin, LOW); // turn the LED off
delay(100); // wait for 100 milliseconds (10th of a second)[/B]
}
}
}
}
