Here's my code. What I'm trying to do is to control leds with a pot.
Accually my code is to long. Please look at it on this website: https://sites.google.com/site/arduinosoapy29/home
When your there, click Code and then the .txt file that's there.
Here's my code. What I'm trying to do is to control leds with a pot.
Accually my code is to long. Please look at it on this website: https://sites.google.com/site/arduinosoapy29/home
When your there, click Code and then the .txt file that's there.
Why don't you go ahead and post your code here. Describe the problem you are having, in detail. Describe what you expect to happen AND what is actually happening.
Sending someone to another website (without providing a proper hyperlink), expecting them to search around your site, and then expecting them to dissect your code (wherever it is) is a high barrier to entry.
My code is to long so I can't post it. Sorry. https://sites.google.com/site/arduinosoapy29/home
I'm simply being super nice to you to trim your fat so your code fits in here. You can go and thank the guy I scolded on the exhibition board. So what's wrong? You want any one of us sane people to look through all these without telling us what the code is for and what the heck is wrong with them?
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
////#include <Servo.h>
//Servo myservo; // create servo object to control a servo
int pot = 5; // analog pin used to connect the potentiometer
int val = 0; // variable to read the value from the analog pin
int delay1= 50*50;
int delay2= 105*105;
int delay3= 75*75;
int loop1= 1; // select the input pin for the potentiometer
//int delay3 = 0; // variable to store the value coming from the sensor
void setup() {
//myservo.attach(5); // attaches the servo on pin 9 to the servo object
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(7, HIGH);
digitalWrite(6, HIGH);
/*delay3 = analogRead(pot);
delay2 = analogRead(pot);
delay1 = analogRead(pot);*/
}
void loop() {
while (loop1 == 1) {
delay3 = analogRead(pot);
delay2 = analogRead(pot);
delay1 = analogRead(pot);
}
/*delay3 = analogRead(sensorPin*13000);
delay2 = analogRead(sensorPin*15000);
delay1 = analogRead(sensorPin*12000);*/
//delay1= val*100;
//delay2= val*500;
//val = analogRead(potpin);
digitalWrite(9, LOW);
delay(delay1);
digitalWrite(9, HIGH);
delay(delay1);
digitalWrite(9, LOW);
delay(delay1);
digitalWrite(9, HIGH);
delay(delay1);
digitalWrite(9, LOW);
delay(delay1);
digitalWrite(9, HIGH);
delay(delay2);
//val = analogRead(potpin);
digitalWrite(11, LOW);
delay(delay1);
digitalWrite(11, HIGH);
delay(delay1);
digitalWrite(11, LOW);
delay(delay1);
digitalWrite(11, HIGH);
delay(delay1);
digitalWrite(11, LOW);
delay(delay1);
digitalWrite(11, HIGH);
delay(delay2);
//val = analogRead(potpin);
digitalWrite(6, LOW);
delay(delay1);
digitalWrite(6, HIGH);
delay(delay1);
digitalWrite(6, LOW);
delay(delay1);
digitalWrite(6, HIGH);
delay(delay1);
digitalWrite(6, LOW);
delay(delay1);
digitalWrite(6, HIGH);
delay(delay2);
//val = analogRead(potpin);
digitalWrite(7, LOW);
delay(delay1);
digitalWrite(7, HIGH);
delay(delay1);
digitalWrite(7, LOW);
delay(delay1);
digitalWrite(7, HIGH);
delay(delay1);
digitalWrite(7, LOW);
delay(delay1);
digitalWrite(7, HIGH);
delay(delay2);
/*delay3 = analogRead(sensorPin*13000);
delay2 = analogRead(sensorPin*15000);
delay1 = analogRead(sensorPin*12000);*/
digitalWrite(9, LOW);
delay(delay1);
digitalWrite(9, HIGH);
delay(delay1);
digitalWrite(9, LOW);
delay(delay1);
digitalWrite(9, HIGH);
delay(delay1);
digitalWrite(9, LOW);
delay(delay1);
digitalWrite(9, HIGH);
delay(delay2);
//val = analogRead(potpin);
digitalWrite(11, LOW);
delay(delay1);
digitalWrite(11, HIGH);
delay(delay1);
digitalWrite(11, LOW);
delay(delay1);
digitalWrite(11, HIGH);
delay(delay1);
digitalWrite(11, LOW);
delay(delay1);
digitalWrite(11, HIGH);
delay(delay2);
//val = analogRead(potpin);
digitalWrite(6, LOW);
delay(delay1);
digitalWrite(6, HIGH);
delay(delay1);
digitalWrite(6, LOW);
delay(delay1);
digitalWrite(6, HIGH);
delay(delay1);
digitalWrite(6, LOW);
delay(delay1);
digitalWrite(6, HIGH);
delay(delay2);
//val = analogRead(potpin);
digitalWrite(7, LOW);
delay(delay1);
digitalWrite(7, HIGH);
delay(delay1);
digitalWrite(7, LOW);
delay(delay1);
digitalWrite(7, HIGH);
delay(delay1);
digitalWrite(7, LOW);
delay(delay1);
digitalWrite(7, HIGH);
delay(delay2);
/*delay3 = analogRead(sensorPin*13000);
delay2 = analogRead(sensorPin*15000);
delay1 = analogRead(sensorPin*12000);*/
digitalWrite(9, LOW);
delay(delay1);
digitalWrite(9, HIGH);
delay(delay1);
digitalWrite(9, LOW);
delay(delay1);
digitalWrite(9, HIGH);
delay(delay1);
digitalWrite(9, LOW);
delay(delay1);
digitalWrite(9, HIGH);
delay(delay2);
//val = analogRead(potpin);
digitalWrite(11, LOW);
delay(delay1);
digitalWrite(11, HIGH);
delay(delay1);
digitalWrite(11, LOW);
delay(delay1);
digitalWrite(11, HIGH);
delay(delay1);
digitalWrite(11, LOW);
delay(delay1);
digitalWrite(11, HIGH);
delay(delay2);
//val = analogRead(potpin);
digitalWrite(6, LOW);
delay(delay1);
digitalWrite(6, HIGH);
delay(delay1);
digitalWrite(6, LOW);
delay(delay1);
digitalWrite(6, HIGH);
delay(delay1);
digitalWrite(6, LOW);
delay(delay1);
digitalWrite(6, HIGH);
delay(delay2);
//val = analogRead(potpin);
digitalWrite(7, LOW);
delay(delay1);
digitalWrite(7, HIGH);
delay(delay1);
digitalWrite(7, LOW);
delay(delay1);
digitalWrite(7, HIGH);
delay(delay1);
digitalWrite(7, LOW);
delay(delay1);
digitalWrite(7, HIGH);
delay(delay2);
/*delay3 = analogRead(sensorPin*13000);
delay2 = analogRead(sensorPin*15000);
delay1 = analogRead(sensorPin*12000);*/
digitalWrite(9, LOW);
delay(delay1);
digitalWrite(9, HIGH);
delay(delay1);
digitalWrite(9, LOW);
delay(delay1);
digitalWrite(9, HIGH);
delay(delay1);
digitalWrite(9, LOW);
delay(delay1);
digitalWrite(9, HIGH);
delay(delay2);
//val = analogRead(potpin);
digitalWrite(11, LOW);
delay(delay1);
digitalWrite(11, HIGH);
delay(delay1);
digitalWrite(11, LOW);
delay(delay1);
digitalWrite(11, HIGH);
delay(delay1);
digitalWrite(11, LOW);
delay(delay1);
digitalWrite(11, HIGH);
delay(delay2);
//val = analogRead(potpin);
digitalWrite(6, LOW);
delay(delay1);
digitalWrite(6, HIGH);
delay(delay1);
digitalWrite(6, LOW);
delay(delay1);
digitalWrite(6, HIGH);
delay(delay1);
digitalWrite(6, LOW);
delay(delay1);
digitalWrite(6, HIGH);
delay(delay2);
//val = analogRead(potpin);
digitalWrite(7, LOW);
delay(delay1);
digitalWrite(7, HIGH);
delay(delay1);
digitalWrite(7, LOW);
delay(delay1);
digitalWrite(7, HIGH);
delay(delay1);
digitalWrite(7, LOW);
delay(delay1);
digitalWrite(7, HIGH);
delay(delay2);
/*delay3 = analogRead(sensorPin*13000);
delay2 = analogRead(sensorPin*15000);
delay1 = analogRead(sensorPin*12000);*/
digitalWrite(9, LOW);
delay(delay3);
digitalWrite(9, HIGH);
delay(delay3);
digitalWrite(7, LOW);
delay(delay3);
digitalWrite(7, HIGH);
delay(delay3);
digitalWrite(6, LOW);
delay(delay3);
digitalWrite(6, HIGH);
delay(delay3);
digitalWrite(11, LOW);
delay(delay3);
digitalWrite(11, HIGH);
delay(delay3);
/*delay3 = analogRead(sensorPin*13000);
delay2 = analogRead(sensorPin*15000);
delay1 = analogRead(sensorPin*12000);*/
digitalWrite(9, LOW);
delay(delay3);
digitalWrite(9, HIGH);
delay(delay3);
digitalWrite(7, LOW);
delay(delay3);
digitalWrite(7, HIGH);
delay(delay3);
digitalWrite(6, LOW);
delay(delay3);
digitalWrite(6, HIGH);
delay(delay3);
digitalWrite(11, LOW);
delay(delay3);
digitalWrite(11, HIGH);
delay(delay3);
/*delay3 = analogRead(sensorPin*13000);
delay2 = analogRead(sensorPin*15000);
delay1 = analogRead(sensorPin*12000);*/
digitalWrite(9, LOW);
delay(delay3);
digitalWrite(9, HIGH);
delay(delay3);
digitalWrite(7, LOW);
delay(delay3);
digitalWrite(7, HIGH);
delay(delay3);
digitalWrite(6, LOW);
delay(delay3);
digitalWrite(6, HIGH);
delay(delay3);
digitalWrite(11, LOW);
delay(delay3);
digitalWrite(11, HIGH);
delay(delay3);
/*delay3 = analogRead(sensorPin*13000);
delay2 = analogRead(sensorPin*15000);
delay1 = analogRead(sensorPin*12000);*/
digitalWrite(9, LOW);
delay(delay3);
digitalWrite(9, HIGH);
delay(delay3);
digitalWrite(7, LOW);
delay(delay3);
digitalWrite(7, HIGH);
delay(delay3);
digitalWrite(6, LOW);
delay(delay3);
digitalWrite(6, HIGH);
delay(delay3);
digitalWrite(11, LOW);
delay(delay3);
digitalWrite(11, HIGH);
delay(delay2);
}
Here's what's wrong. I have a circuit with LEDs and a potentiometer. What I'm trying to do is change the speed on which the LEDs blink. I used an example code to get me started, but it doesn't have a while loop in it to keep on checking the potentiometer. I tried to make it work but it doesn't. Do I need to add a delay(500) in it after the get analog? :-/
So... cut your code down to that simple example of "while loop in it to keep on checking the potentiometer." Post what IS happening and what you EXPECT to happen.
We can help you narrow that down. Otherwise, you won't be able to get much assistance.
Well right now I'm on my iPod so I'll try to do my best. Right now when I turn it on it just sits and does nothing. Everything is wired right cause I can run the examples just fine. The code looks kinda like this:
void loop(){
While(1==1){;
"Get the value of pot here"
}
It doesn't look just like this. It's way different. Sorry ![]()
Wait nevermind here's the code:
void setup() {
//myservo.attach(5); // attaches the servo on pin 9 to the servo object
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(7, HIGH);
digitalWrite(6, HIGH);
/*delay3 = analogRead(pot);
delay2 = analogRead(pot);
delay1 = analogRead(pot);*/
}
void loop() {
while (loop1 == 1) {
delay3 = analogRead(pot);
delay2 = analogRead(pot);
delay1 = analogRead(pot);
}
Well right now I'm on my iPod so I'll try to do my best. Right now when I turn it on it just sits and does nothing
You can do better by posting code from your computer and explaining, in detail, what "nothing" is.
If you put in zero effort in asking the questions, don't expect much more in the replies.
Nothing is it doesn't do anything. None of the LEDs light(only power). It's strange...
Question: How do I get the potentiometer and the programming to work right?
You can start by replacing some of the ugly blocks with loops.
your not specifying types for your loop's
Those last two posts made mo sence. But here's my code without all the comments. It's not the whole program, it's just the part that doesn't work. If you comment out the getAnalog(), it works just fine. There are some variables that are not shown, but everything is on my website under code.
void setup() {
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(7, HIGH);
digitalWrite(6, HIGH);
}
void loop() {
while (loop1 == 1) {
delay3 = analogRead(pot);
delay2 = analogRead(pot);
delay1 = analogRead(pot);
}
Those last two posts made mo sence
So does your's ![]()
do this
void loop()
{
digitalwrite(3,high);
// set all the led's here
analogRead(pot pin);
delay (pot value)
digitalWrite(LOW);
}
-Hope this makes sence ![]()
while (loop1 == 1) {
delay3 = analogRead(pot);
delay2 = analogRead(pot);
delay1 = analogRead(pot);
}
Since nothing in the loop changes the value of loop1, and since loop1 is initially assigned a value of 1, how do you expect to ever advance beyond this while loop?
Perhaps you want this to be
[glow]if [/glow](loop1 == 1) {
delay3 = analogRead(pot);
delay2 = analogRead(pot);
delay1 = analogRead(pot);
}
Yes, that works, but it only checks it when it has gone through the loop. I'll try putting them every so often around the code. Thanks! ![]()
Question:
I'm trying to use a while true do statment and it's not working. (Yes, I am a newb so you don't have to yell at me anymore. ;)) Here is what I have:
while true do{
delay3 = analogRead(pot);
delay2 = analogRead(pot);
delay1 = analogRead(pot);
}
while (true){
Lol why couldn't I think of that! Thanks! ![]()
Problem, it doesn't work...
while (true){
delay3 = analogRead(pot);
delay2 = analogRead(pot);
delay1 = analogRead(pot);
}
Problem, it doesn't work...
Define "work"
Sorry. Nothing happens on the Arduino. It downloads the code just fine. Only the power light is on.