I'm trying to get a subroutine to interrupt the loop and restart from the beginning. I've tried various ways to use Interrupts to do this, and after reading the forums have decided there probably isn't a way to do it like that (my first attempts would just stop but not restart it).
My main loop is about 10 seconds long, but I want to be able to stop and restart it whenever a reset button is pressed.
Here is my code (abridged):
#include <Arduino.h>
#include "ST7036.h"
#include "LCD_C0220BiZ.h"
#include <Wire.h>
//LCD_C0220BIZ lcd = LCD_C0220BIZ ( );
ST7036 lcd = ST7036 ( 2, 20, 0x78 );
const int lcd_resetPin = 8;
const int resetPin = 2;
void setup ()
{
pinMode(lcd_resetPin, OUTPUT);
pinMode(resetPin, INPUT_PULLUP);
digitalWrite(lcd_resetPin, LOW);
digitalWrite(lcd_resetPin, HIGH);
Serial.begin ( 57600 );
lcd.init ();
lcd.setContrast(10);
}
void reset()
{
lcd.clear();
lcd.setCursor (0,0);
lcd.print("Sing Sing Sing!");
delay (1000);
}
void alphabet()
{
//prints the alphabet
}
void loop()
{
//something to reset in the middle of the alphabet
alphabet();
}
This is just a test code to figure out what I'm doing, the actual application will be to reset a counter on a motor controller, but I also wanted to have it print "RESET COUNT", which is where I ran into trouble.
I don't see where you are trying to print from the ISR (reset()).
You don't have to attach the interrupt every time through loop(). Just do it once in setup(). Look at the syntax for attachInterrupt. The interrupt number is not the pin number.
If you do try to print in an ISR, Serial.print depends on interrupts. Interrupts are disabled during an ISR.
You obviously have not studied the links in Reply #2.
The demo Several Things at a Time is an extended example of BWoD and illustrates the use of millis() to manage timing without blocking. It may help with understanding the technique.
And you can print the alphabet with a few lines of code - something like this
I totally did not know that about printing the alphabet!
From what I understand about the BWoD and Several things at a time, the idea is to avoid using delay whenever possible and use millis() instead. I'll try that.