Leo-zhong
Published © GPL3+

Balance maze with Arduino Uno

This is a balanced maze with sensors, and you can only win if you stay calm and balanced.

BeginnerFull instructions provided2 hours592
Balance maze with Arduino Uno

Things used in this project

Story

Read more

Schematics

Sensors' connection

it's easy to connect according to your way.

Code

Key code

C/C++
The main code can be optimized
void setup() {
    pinMode(TouchPin, INPUT);
    pinMode(TouchPin1, INPUT);
    pinMode(ledPin,OUTPUT);
    pinMode(buttonPin, INPUT);
    tm1637.set();
    tm1637.init();
    Timer1.initialize(500000);//timing for 500ms
    Timer1.attachInterrupt(TimingISR);//declare the interrupt serve routine:TimingISR
}


void loop(){
    int sensorValue = digitalRead(TouchPin);
    int sensorValue1 = digitalRead(TouchPin1);
    int buttonState = digitalRead(buttonPin);
    if(sensorValue==HIGH && sensorValue1==HIGH)
    {
        digitalWrite(ledPin,LOW);
        if(buttonState == HIGH)
        {
          if(Update == ON)
         {
            TimeUpdate();
            tm1637.display(TimeDisp);
          } 
         }
         else
         {
            exit(0);
         }
    }
    else
    {
        digitalWrite(ledPin,HIGH);
    }
}

void TimeUpdate(void)
{
  if(ClockPoint)
    tm1637.point(POINT_ON);
  else 
   tm1637.point(POINT_OFF);
   
   TimeDisp[0] = minute / 10;
   TimeDisp[1] = minute % 10;
   TimeDisp[2] = second / 10;
   TimeDisp[3] = second % 10;
   Update = OFF;
}

void TimingISR()
{
  halfsecond ++;
  Update = ON;
  if(halfsecond == 2)
  {
    second --;
    if(second == 0 && minute !=0)
    {
      minute --;
      if(minute == 0)
      {
      second = 59;
      }
    }
    halfsecond = 0;
    Serial.println(second);
    ClockPoint = (~ClockPoint) & 0x01;
  }
}

Credits

Leo-zhong

Leo-zhong

2 projects • 2 followers

Comments