Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

how to control delay speed with a push button arduino

Im currently working on an arduino project and was trying to get a disco light sequence working with push button speed control but I can't seem to get it to work here is my push button code im sorry if the code is a bit meessy i am new to arduino and i cant seem to get my code right please be patient if i dont understand what you are sugesting as i also am autistic so i dont get some things imediatly

pinMode(12, INPUT);
}
int del=1000;
void loop()
{
  int val = digitalRead(12);
  if(val==HIGH)
    del = 500;
  else if(val==LOW)
    del = del;

And here is my disco lights code

void setup()
{
  pinMode(13, OUTPUT);
  pinMode(0, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  
}
void loop()
{
  val = analogRead(potp);
  digitalWrite(13, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(13, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(0, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(0, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(11, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(11, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(10, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(10, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(9, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(9, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(8, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(8, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(7, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  delay(val+1);
  val = analogRead(potp);
  digitalWrite(7, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(7, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(8, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(8, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(9, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(9, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(10, HIGH);
  val = analogRead(potp);
  delay(val+100);;
  val = analogRead(potp);
  digitalWrite(10, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(11, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(11, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(0, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(0, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(13, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(13, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  delay(val+1);
  val = analogRead(potp);
  digitalWrite(13, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(13, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(0, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(0, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(11, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(11, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(10, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(10, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(9, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(9, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(8, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(8, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(7, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(7, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(7, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(8, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(8, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(9, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(9, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(10, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(10, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(11, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(11, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(0, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(0, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(13, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(13, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  delay(val+1);
  val = analogRead(potp);
  digitalWrite(13, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(13, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(0, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(0, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(11, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(11, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(10, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(10, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(9, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(9, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(8, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(8, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(7, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  delay(val+1);
  val = analogRead(potp);
  digitalWrite(7, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(7, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(8, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(8, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(9, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(9, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(10, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(10, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(11, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(11, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(0, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(0, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(13, HIGH);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  digitalWrite(13, LOW);
  val = analogRead(potp);
  delay(val+100);
  val = analogRead(potp);
  delay(val+1);
  val = analogRead(potp);
  digitalWrite(13, HIGH);
  val = analogRead(potp);
  delay(val+1000);
  val = analogRead(potp);
  digitalWrite(0, HIGH);
  val = analogRead(potp);
  delay(val+1000);
  val = analogRead(potp);
  digitalWrite(11, HIGH);
  val = analogRead(potp);
  delay(val+1000);
  val = analogRead(potp);
  digitalWrite(10, HIGH);
  val = analogRead(potp);
  delay(val+1000);
  val = analogRead(potp);
  digitalWrite(9, HIGH);
  val = analogRead(potp);
  delay(val+1000);
  val = analogRead(potp);
  digitalWrite(8, HIGH);
  val = analogRead(potp);
  delay(val+1000);
  val = analogRead(potp);
  digitalWrite(7, HIGH);
  val = analogRead(potp);
  delay(val+1000);
  val = analogRead(potp);
  delay(val+1);
  val = analogRead(potp);
  digitalWrite(7, LOW);
  val = analogRead(potp);
  delay(val+1000);
  val = analogRead(potp);
  digitalWrite(8, LOW);
  val = analogRead(potp);
  delay(val+1000);
  val = analogRead(potp);
  digitalWrite(9, LOW);
  val = analogRead(potp);
  delay(val+1000);
  val = analogRead(potp);
  digitalWrite(10, LOW);
  val = analogRead(potp);
  delay(val+1000);
  val = analogRead(potp);
  digitalWrite(11, LOW);
  val = analogRead(potp);
  delay(val+1000);
  val = analogRead(potp);
  digitalWrite(0, LOW);
  val = analogRead(potp);
  delay(val+1000);
  val = analogRead(potp);
  digitalWrite(13, LOW);
  val = analogRead(potp);
  delay(val+1000);
  
  
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...