//Example - Exernal interrupt
#include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g;
#define LED 13
int toggle=0;
const uint8_t rook_bitmap[] U8G_PROGMEM = {
0x00, // 00000000
0x55, // 01010101
0x7f, // 01111111
0x3e, // 00111110
0x3e, // 00111110
0x3e, // 00111110
0x3e, // 00111110
0x7f // 01111111
};
const uint8_t clear_bitmap[] U8G_PROGMEM = {
00000000, // 00000000
01100110, // 01010101
11111111, // 01111111
01111110, // 00111110
00111100, // 00111110
00011000, // 00111110
00010000, // 00111110
00000000 // 01111111
};
void setup() {
// put your setup code here, to run once:
Serial.begin(115200); // setup serial
pinMode(LED, OUTPUT); // setup output
attachInterrupt(2,displaymic,RISING); //start the int.0 // opton 1 to configure hardware/external interupt
// attachInterrupt(digitalPinToInterrupt(21), displaymic,RISING); // option 2
}
//ISR - external interupt
void displaymic(){
Serial.write("micros = ");
Serial.println("button pressed");
Serial.println(micros());
toggle=!toggle;
// delay(300);
}
void draw() {
// graphic commands to redraw the complete screen should be placed here
u8g.drawBitmapP( 0, 0, 1, 8, rook_bitmap);
}
void clear(void){
u8g.drawBitmapP(20, 20, 1, 8, clear_bitmap);
Serial.println("heart");
}
void loop() {
// put your main code here, to run repeatedly:
// turn on/off LED
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
Serial.print("toggle: ");
Serial.println(toggle);
u8g.firstPage(); //marks the beginning of the picture loop.
do {
u8g.setColorIndex(1); // set the colour to white
if (toggle==1){
draw();
Serial.println("rook");
}
/* else if (toggle==2){
u8g.drawTriangle(14,40, 45,15, 70,40);
Serial.println("triangle");
}
else if (toggle==3){
u8g.drawBox(10,10, 50, 50);
Serial.println("square");
}
else{
clear();
Serial.println("blank");
*/
} while ( u8g.nextPage() ); //marks the end of the body of the picture loop
delay(1000);
}