hi
i am trying to wright a code, but it just wont retur to start as i want it to.
i want to push the button, then it does something, then push it again, and it returns to zero, and so on.
here is my code so far:
#include "U8glib.h"
U8GLIB_LD7032_60x32 u8g(9, 8, 11, 10, 12);
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 3; // variable to store the servo position
const int led1Pin = 4;
const int led2Pin = 5;
int flag1 = 0;
int switchPin = 2; // switch is connected to pin 2
int val; // variable for reading the pin status
int buttonState; // variable to hold the button state
int lightMode = 0; // Is the light on or off?
unsigned long previousMillis1 = 0;
long LEDTime = 500;
void setup() {
myservo.attach(3); // attaches the servo on pin 9 to the servo object
pinMode(switchPin, INPUT); // Set the switch pin as input
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
Serial.begin(9600); // Set up serial communication at 9600bps
buttonState = digitalRead(switchPin); // read the initial state
}
const uint8_t rook_bitmap[] PROGMEM = {
0x00, // 00000000
0x55, // 01010101
0x7f, // 01111111
0x3e, // 00111110
0x3e, // 00111110
0x3e, // 00111110
0x3e, // 00111110
0x7f // 01111111
};
void loop(){
Serial.print("Read switch input: ");
Serial.println(digitalRead(switchPin)); // Read the pin and display the value
delay(100);
unsigned long currentMillis = millis();
val = digitalRead(switchPin); // read input value and store it in val
if (val != buttonState) { // the button state has changed!
if (val == HIGH) { // check if the button is pressed
if (flag1 == 0) { // light is off
flag1 = 1; // light is on!
if (flag1 == 1) {
// picture loop
u8g.firstPage();
do {
u8g.setFont(u8g_font_unifont);
// u8g.setFont(u8g_font_osb21);
u8g.drawStr( 5, 20, "KILL");
} while ( u8g.nextPage() );
delay(1500);
u8g.firstPage();
do {
u8g.setFont(u8g_font_unifont);
// u8g.setFont(u8g_font_osb21);
u8g.drawStr( 5, 20, "RASMUS");
} while ( u8g.nextPage() );
delay(1500);
u8g.firstPage();
do {
u8g.drawCircle(30, 20, 18);
u8g.drawEllipse(26, 12, 7, 5,U8G_DRAW_UPPER_LEFT );
u8g.drawEllipse(34, 12, 7, 5, U8G_DRAW_UPPER_RIGHT);
u8g.drawTriangle(30,14, 27, 18, 33, 18);
u8g.drawFilledEllipse( 30, 25, 10,5, U8G_DRAW_LOWER_LEFT);
u8g.drawFilledEllipse( 30, 25, 10,5, U8G_DRAW_LOWER_RIGHT);
u8g.drawLine(30, 13, 30, 16);
u8g.drawFrame(0, 0,60 ,32);
} while ( u8g.nextPage() );
delay(2000);
u8g.firstPage();
do {
u8g.drawBitmapP(30, 16,1, 8, rook_bitmap);
} while ( u8g.nextPage() );
delay(1000);
u8g.firstPage();
do {
} while ( u8g.nextPage() );
delay(1000);
flag1 = 2;
}
else if (val != buttonState) { // the button state has changed!
if (val == HIGH) { // check if the button is pressed
if (flag1 == 2) { // light is off
flag1 = 0; // light is on!
}}}
buttonState = val; // save the new state in our variable
}
}}}