Here are my latest attempts.
//**************************************************************************************
// Digistump by Digispark or Arduino MEGA2560 Digispark development platform
// HeelerPod.ino Active High
// unplug and plug, press upload and read console prompt to insert digispark
// Bitrate 57600
//**************************************************************************************
/*
This for Interrupt driven code!
The Arduino sketch begins with the execution of C++ int main() function in the background and intializes many modules including Timer-0. This is the reason for the compilation error in your sketch of post #1.
What I have done in post #40 is that I have bypassed that backgorund C++ int main() function; instead, I have invoked my own int main() function so that Timer-0 is no more initialized with values that conflict with the purpose of your sketch of post #1.
Now, the millis() function will not work which is no good. It is better to re-design your sketch using Timer-2 and let the background C++ int main() function run and millis() function work.
*/
#define digispark true // !!!!!!!!!!!!!!!!!!!!!! Remember to match processor !!!!!!!!!!!!!!!!!!!
#define flicker 0 // Led by default. Long LOW is Reset. Nay nay! Do not use
#define mosfet 1
#define msb 2
#define lsb 3
#define test 4 // Test: Sets off timing to 5 per second, pin 1 has an LED tide high
//define reset 5
int delayval = 11738; // microseconds Brain LED 40hz half cycle not specific
//int delayval = 59; // microseconds StunGun 6.5khz half cycle not specific
//int delayval = 23; // microseconds Ringing 21.4khz half cycle not specific
//int delayval = 14; // microseconds Ringing 32.4khz half cycle not specific
//The instruction cycle time has an effect on the timing.
int ontime = 500; // milliseconds Pod OnTime = 0.5 second
int waitinterval = 900; // wait is in milliseconds. 900 seconds equal 15 minutes
//**********************************************************************
//**********************************************************************
//** Use the Minutes amount to control all time variants
//**********************************************************************
//**********************************************************************
// minute variables for short testing, otherwise should be 1
// 1=60, .75=45, .50=30, .25=15, .125=7.5, .0625=3.75, .03125=1.5, .012625 =.75, .01225=.5, .006125=.25, .0030625=.125, .00153125=.06125
float minutes = .006125;
float seconds = minutes * 60;
float milliseconds = seconds * 1000;
//**********************************************************************
// Print a string
//**********************************************************************
void printstr(String param, String newline){
if(!digispark){
Serial.print(param);
if(newline == "nl"){Serial.println("");}
}
}
//**********************************************************************
// The setup routine runs once when you press reset:
//**********************************************************************
void PodTimerSetup() {
Serial.begin(57600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
//Serial.println("Test started!");
//
//pinMode(0, INPUT); //Avoid for the Mega2560
//pinMode(1, OUTPUT); //Avoid for the Mega2560
pinMode(flicker, OUTPUT); // Test Delay offtime
pinMode(mosfet, OUTPUT); // Mosfet shield 1
pinMode(lsb, INPUT_PULLUP); //LSB Time interval switches 3
pinMode(msb, INPUT_PULLUP); //MSB Time interval switches 2
pinMode(test, INPUT_PULLUP); //High speed output endable
if(!digispark){
printstr("","nl");
printstr("********************************************************************************************************", "nl");
printstr("Operation begin", "nl");
printstr("**************************", "nl");
}
intervalsetting();
poweron();
}
//**********************************************************************
// the loop routine runs over and over again forever:
//**********************************************************************
void mainloop() {
while (1){
//emppulse();
}
}
//**********************************************************************
// Single pulse routine
//**********************************************************************
void emppulse(){
float offtime = 0;
digitalWrite(mosfet, HIGH); // turn the LED on (HIGH is the voltage level)
delay(ontime); // 500 milliseconds
digitalWrite(mosfet, LOW); // turn the LED off by making the voltage LOW
// digitalread == low when development platform switch is ON.
// digitalread == low when digispark heeler pod jumper is connecting the 2 pins, i.e. Pin is low.
if(digitalRead(test) == HIGH){ //switch off
offtime = timingswitches();
if(!digispark){
printstr("Standard timing sequence selected", "nl"); // Test mode short interval
printstr("After: ", "");
printstr(String(offtime), "");
printstr(" Divide this by ~110 for seconds", "nl");
}
}
else{
offtime = timingswitches();
if(!digispark){
printstr("TEST sequence selected: ", "");
printstr(" offtime: ", "");
printstr(String(offtime), "nl");
}
}
// ===============================================================
delay(offtime); // unsigned Long millseconds 900,000 = 15 minutes, wait till next pulse, production
// OR for debugging
//for(int i=0; i < 4000; i++){digitalWrite(flicker, LOW);printstr("countdown: ","");printstr(String(i),"nl");digitalWrite(flicker, HIGH);}
// ===============================================================
}
//**********************************************************************
// Read switches for offtime delays
//**********************************************************************
int timingswitches() {
int switchcount = (digitalRead(msb) * 2 + digitalRead(lsb)) + 1; //msb, lsb
if(!digispark){
printstr("switchcount = [msb=dr2 + lsb=dr3] +1, test=dr0", "nl");
printstr(String(switchcount), "");
printstr(" = [", "");
printstr(String(digitalRead(msb)), "");
printstr(", ", "");
printstr(String(digitalRead(lsb)), "");
printstr("], ", "");
printstr(String(digitalRead(test)),"");
printstr(", timingswitches()=", "");
printstr(String(milliseconds),"nl");
}
// 900 seconds, 900,000 milliseconds = 15 minutes
int tempinterval = 0; // default base setting
tempinterval = switchcount * milliseconds;
return tempinterval;
}
//**********************************************************************
// Sets milliseconds by the minutes varialble
//**********************************************************************
void intervalsetting(){
if(!digispark){printstr("This is not Digispark", "nl");}
minutes = .25; //default value for groups of 15 minutes
if(digitalRead(test) == LOW){ // Test mode short interval
minutes = .006125; //short value for high speed test
if(!digispark){printstr("Short interval test initiated", "nl");}
}
else {
if(!digispark){
//val = digitalRead(test);
if(digitalRead(test) == HIGH) {
printstr("Standard time setting initiated: dr5=", "");
printstr(String(digitalRead(test)), "nl");
}
}
}
seconds = minutes * 60;
milliseconds = seconds * 1000;
if(!digispark){
printstr("milliseconds=", "");
printstr(String(milliseconds), "nl");
}
}
//**********************************************************************
// One time power setup routine as a power on indicator
//**********************************************************************
void poweron(){
if(!digispark){printstr("**************************", "nl");}
int pwsave = milliseconds;
milliseconds = .005;
//timingswitches();
for(int i = 0; i<3; i++){
if(!digispark){printstr("Power on pulse", "nl");}
emppulse();
}
milliseconds = pwsave;
//timingswitches();
if(!digispark){
printstr("Power on sequence finished", "nl");
printstr("**************************", "nl");
printstr("Normal operation will begin", "nl");
printstr("", "nl");
}
}
//**********************************************************************
void led(){
//digitalWrite(1, LOW); // turn the LED off (HIGH is the voltage level)
//digitalWrite(3, LOW); // turn the LED off (HIGH is the voltage level)
//digitalWrite(4, LOW); // turn the LED off (HIGH is the voltage level)
//digitalWrite(5, LOW); // turn the LED off (HIGH is the voltage level)
//delay(2000); // in Milliseconds. There are 1000 in a second
//digitalWrite(1, HIGH); // turn the LED on (HIGH is the voltage level)
//digitalWrite(3, HIGH); // turn the LED on (HIGH is the voltage level)
//digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
//digitalWrite(5, HIGH); // turn the LED on (HIGH is the voltage level)
//delay(500); // in Milliseconds. There are 1000 in a second
}
//**********************************************************************
void stun(){}
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
int intr_count = 0;
int sec = 0;
ISR(TIMER0_OVF_vect) //Interrupt vector for Timer0
{
if( intr_count == 63 ) //waiting for 63 because to get 1 sec delay
{
PORTB ^= (1 << PB1); //toggling the LED
intr_count = 0; //making intr_count=0 to repeat the count
++sec;
} else intr_count++; //incrementing c upto 63
}
void timer_setup() {
DDRB |= (1 << PB1); // set PB1 as output(LED)
TCCR0A = 0x00; //Normal mode
TCCR0B = 0x00;
TCCR0B |= (1 << CS00) | (1 << CS02); //prescaling with 1024
sei(); //enabling global interrupt
TCNT0 = 0;
TIMSK |= (1 << TOIE0); //enabling timer0 interrupt
PORTB |= (1 << PB1);
}
int main() {
PodTimerSetup();
timer_setup();
mainloop();
}
void setup(){} // Null for Interrupt code. Gotten from my posts in Arduino forum
void loop(){} // Null for Interrupt code Gotten from my posts in Arduino forum
Compile #1 worked.
Compile #2 produced this.
FQBN: digistump:avr:digispark-tiny
Using board 'digispark-tiny' from platform in folder: C:\Users\phyzx\AppData\Local\Arduino15\packages\digistump\hardware\avr\1.7.5
Using core 'tiny' from platform in folder: C:\Users\phyzx\AppData\Local\Arduino15\packages\digistump\hardware\avr\1.7.5
Detecting libraries used...
Using cached library dependencies for file: C:\Users\phyzx\AppData\Local\arduino\sketches\B989537E2FFEDDED381696957CA77415\sketch\HeelerPodV3.ino.cpp.merged
Generating function prototypes...
Using cached sketch with function prototypes.
Compiling sketch...
Using previously compiled file: C:\Users\phyzx\AppData\Local\arduino\sketches\B989537E2FFEDDED381696957CA77415\sketch\HeelerPodV3.ino.cpp.o
Compiling libraries...
Compiling core...
Using previously compiled file: C:\Users\phyzx\AppData\Local\arduino\sketches\B989537E2FFEDDED381696957CA77415\core\pins_arduino.c.o
Using precompiled core: C:\Users\phyzx\AppData\Local\arduino\cores\f9a23a9591584bf3e859390c170928cd\core.a
Linking everything together...
"C:\Users\phyzx\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-gcc" -Os -g -Wl,--gc-sections -mrelax -fmerge-all-constants -mmcu=attiny85 -o "C:\Users\phyzx\AppData\Local\arduino\sketches\B989537E2FFEDDED381696957CA77415/HeelerPodV3.ino.elf" "C:\Users\phyzx\AppData\Local\arduino\sketches\B989537E2FFEDDED381696957CA77415\sketch\HeelerPodV3.ino.cpp.o" "C:\Users\phyzx\AppData\Local\arduino\sketches\B989537E2FFEDDED381696957CA77415\core\pins_arduino.c.o" "C:\Users\phyzx\AppData\Local\arduino\cores\f9a23a9591584bf3e859390c170928cd\core.a" "-LC:\Users\phyzx\AppData\Local\arduino\sketches\B989537E2FFEDDED381696957CA77415" -lm
C:\Users\phyzx\AppData\Local\Arduino15\packages\digistump\hardware\avr\1.7.5\cores\tiny\wiring.c: In function 'delay':
lto-wrapper.exe: fatal error: C:\Users\phyzx\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-gcc returned 1 exit status
compilation terminated.
c:/users/phyzx/appdata/local/arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld.exe: error: lto-wrapper failed
collect2.exe: error: ld returned 1 exit status
exit status 1
Compilation error: exit status 1
Compile #3 produced this:
FQBN: digistump:avr:digispark-tiny
Using board 'digispark-tiny' from platform in folder: C:\Users\phyzx\AppData\Local\Arduino15\packages\digistump\hardware\avr\1.7.5
Using core 'tiny' from platform in folder: C:\Users\phyzx\AppData\Local\Arduino15\packages\digistump\hardware\avr\1.7.5
Detecting libraries used...
Using cached library dependencies for file: C:\Users\phyzx\AppData\Local\arduino\sketches\B989537E2FFEDDED381696957CA77415\sketch\HeelerPodV3.ino.cpp.merged
Generating function prototypes...
Using cached sketch with function prototypes.
Compiling sketch...
Using previously compiled file: C:\Users\phyzx\AppData\Local\arduino\sketches\B989537E2FFEDDED381696957CA77415\sketch\HeelerPodV3.ino.cpp.o
Compiling libraries...
Compiling core...
Using previously compiled file: C:\Users\phyzx\AppData\Local\arduino\sketches\B989537E2FFEDDED381696957CA77415\core\pins_arduino.c.o
Using precompiled core: C:\Users\phyzx\AppData\Local\arduino\cores\f9a23a9591584bf3e859390c170928cd\core.a
Linking everything together...
"C:\Users\phyzx\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-gcc" -Os -g -Wl,--gc-sections -mrelax -fmerge-all-constants -mmcu=attiny85 -o "C:\Users\phyzx\AppData\Local\arduino\sketches\B989537E2FFEDDED381696957CA77415/HeelerPodV3.ino.elf" "C:\Users\phyzx\AppData\Local\arduino\sketches\B989537E2FFEDDED381696957CA77415\sketch\HeelerPodV3.ino.cpp.o" "C:\Users\phyzx\AppData\Local\arduino\sketches\B989537E2FFEDDED381696957CA77415\core\pins_arduino.c.o" "C:\Users\phyzx\AppData\Local\arduino\cores\f9a23a9591584bf3e859390c170928cd\core.a" "-LC:\Users\phyzx\AppData\Local\arduino\sketches\B989537E2FFEDDED381696957CA77415" -lm
lto1.exe: internal compiler error: invalid resolution in the resolution file
Please submit a full bug report,
with preprocessed source if appropriate.
See https://gcc.gnu.org/bugs/ for instructions.
lto-wrapper.exe: fatal error: C:\Users\phyzx\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-gcc returned 1 exit status
compilation terminated.
c:/users/phyzx/appdata/local/arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld.exe: error: lto-wrapper failed
collect2.exe: error: ld returned 1 exit status
exit status 1
Compilation error: exit status 1
Compile #4 worked
Compile and upload #1: Compile worked but upload hangs when I plug the Digispark in.