Hello All,
I am a newbie at this and am working on my first real program. I have written an Arduino sketch that is doing what I want it to do and am going to upload to an ATTiny 45 using the TINY AVR programmer. I have pasted the code below.
Does anyone see any problems in the code that might cause a problem on the ATTiny 45 or some improvements to the code?
Thanks in advance,
Jeff
/*
This code reads JP1 and JP2 (Delay Select Jumpers) to determine the chosen tube warm-up delay
according to the table below.
JP1 JP2 DELAY(s) DELAY(ms)
HIGH HIGH 75 75000
LOW HIGH 90 90000
HIGH LOW 105 105000
LOW LOW 120 120000
Once the delay time is determined, the code waits for the appropriate number of milliseconds
using the millis(s) function. After the selected amount of time has elapsed, the the TXEnable
pin is switched HIGH to alllow the amplifier to operate.
*/
//Define variables that do not change
const int DelaySelectPin1 = 4;
const int DelaySelectPin2 = 5;
const int TXEnablePin = 6;
//Define variables that do change
int DelaySelectPin1Val = 0;
int DelaySelectPin2Val = 0;
unsigned long DelayVal = 0;
unsigned long DelayTime = 0;
void setup() {
//Define pins and pin modes
pinMode (DelaySelectPin1, INPUT_PULLUP);
pinMode (DelaySelectPin2, INPUT_PULLUP);
pinMode (TXEnablePin, OUTPUT);
//activate serial port for debugging
Serial.begin(9600);
//Read the 2 delay select jumpers (JP1 and JP2) to determine what the delay value is in milliseconds
DelaySelectPin1Val = digitalRead(DelaySelectPin1);
DelaySelectPin2Val = digitalRead(DelaySelectPin2);
if (DelaySelectPin1Val == HIGH && DelaySelectPin2Val == HIGH) {
DelayVal = 75000;
}
else if (DelaySelectPin1Val == LOW && DelaySelectPin2Val == HIGH) {
DelayVal = 90000;
}
else if (DelaySelectPin1Val == HIGH && DelaySelectPin2Val == LOW) {
DelayVal = 105000;
}
else {
DelayVal = 120000;
}
//debugging section for verification of timer length
Serial.print(DelaySelectPin1Val);
Serial.println(DelaySelectPin2Val);
delay(5000);
Serial.println(DelayVal);
Serial.println("START");
}
void loop() {
unsigned long currentMillis = millis();
//Delay for the required number of millisecondshen and then enable the TXEnable pin
Serial.println(currentMillis);
if (currentMillis >= DelayVal) {
DelayTime = DelayVal/1000;
Serial.print(DelayTime);
Serial.println(" second delay");
digitalWrite(TXEnablePin,HIGH);
delay(500);
//Stop execution of the loop code and put the controller into endless loop until power-off and new power-on condition
while(1);
}
}