#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
int laser;
int laser_step;
unsigned int timerstart;
unsigned int timerinterval;
unsigned int currenttime;
void setup() {
// put your setup code here, to run once:
lcd.begin(16,2);
laser=0;
laser_step=0;
lcd.setCursor(0,0);
lcd.print("* * * * * * * *");
pinMode(7, INPUT_PULLUP);
timerstart=millis();
timerinterval=250;
}
void loop() {
// put your main code here, to run repeatedly:
currenttime=millis();
if((currenttime-timerstart>timerinterval))
{
//reset
timerstart=currenttime;
lcd.setCursor(laser,1);
lcd.print(" ");
if(laser==15)
{
laser_step=-1;
}
else if(laser==0)
{
laser_step=1;
}
laser+=laser_step;
lcd.setCursor(laser,1);
lcd.print("^");
}
// check the button for stars
if(digitalRead(7)==LOW)
{
lcd.setCursor(laser,0);
lcd.print(" ");
}
delay(500);
}