Hey guys
i have just learned how to controll led brithness with my arduino but ill have to learn more so i have to ask for one more sketch for my attiny
I really need something that is like : if there is a button pressed then if in the COMMING ten seconds there was ANY voltage on ground and some analog pin for any length of time AND if there was a button pressed in those same ten seconds then brithen the led else if the other button was pressed in those ten seconds (AND THERE WAS A PULSE! in those 10 seconds) make the led less brither, else else if nothing happend during the ten seconds do nothing. Thanks SO much this is btw for a project involving neural networks ![]()
Try the sketch I made in Reply# 3, in this link.
The Idea is very similar, in which it looks for a button press then it goes into a while loops that acts as a count down clock, but in that time, it blinks an LED.
You however, can change it to look for more button press and other pins too.
http://forum.arduino.cc/index.php?topic=325672.msg2249286#msg2249286
I think it would help you (most importantly) and us if you write your requirements more clearly. Put each requirement on a separate line in chronological order.
It sounds like you have some inter-linked IF clauses and it is easy to get them wrong.
...R
Oke, sorry.
First a button is pressed.
That makes a 10 second while.
If in those 10 seconds a voltage for any length of time is apllied. (it will be a pulse the voltage)
Only do the functions of these buttons if there was a voltage!
AND if one other button is pressed make the led less brither.
Or if one other OTHER button is pressed make the led brither
If noting hapens wheter there was voltage or not do nothing.
ALL of this happens in 10 seconds
![]()
Thanks! ![]()
Nooooooo i said something wrong!
Do not make the led brither or less brither.
I mean there is a voltage on two pins ground and some other pin.
And that voltage Can be made more i mean with britheness make the voltage more.
And with less brither i mean make the voltage less.
Sorry for all the confusion..
Thanks!
Haduvokone:
Nooooooo i said something wrong!
Please just write it all out (in a new Post) without any errors. The comparison with your existing post will probably be useful.
...R
There is a voltage on two pins that will be adjusted later
First a button is pressed.
That makes a 10 second while.
If in those 10 seconds a voltage for any length of time is apllied. (it will be a pulse, the voltage)
Only do the functions of these buttons if there was a voltage in those ten seconds!!
AND if one other button is pressed lessen the voltage.
Or if one other OTHER button is pressed up the voltage
If noting hapens wheter there was voltage or not do nothing.
ALL of this happens in 10 seconds.
Thanks!
![]()
Hi,
How many buttons do you have?
Start button
Functions
Brightness UP button
Brightness Down button
So you want the Start button to allow any of the function buttons to work in a 10 second period.
Tom..... ![]()
Haduvokone:
There is a voltage on two pins that will be adjusted laterFirst a button is pressed.
That makes a 10 second while.
If in those 10 seconds a voltage for any length of time is apllied. (it will be a pulse, the voltage)
I am concerned about your use of the word WHILE. Almost certainly the use of while() in your Arduino code would not be appropriate at that point.
I think a better description might be as follows (but PLEASE tell us if I have misunderstood)
First a button is pressed.
If, within the next 10 seconds a voltage for any length of time is apllied. (it will be a pulse, the voltage)
I have not studied the rest of your logic as I want to see your reply to @TomGeorge's question
...R
Thanks! ![]()
Yes those are the buttons ![]()
You just set me thinking!! This can be done way simpler!! ![]()
There will be a voltage between two output pins
A voltage (a pulse) is applied to two INPUT pins that starts a ten second time period in those ten seconds two
buttons will work, One Increases the voltage on the two output pins the other decreases the voltage on the two output pins.
The buttons will only work in that 10 seconds time period.
When one of those buttons is pressed in the time that does not mean that the period is over!
There can be as many presses on those buttons asslong as it is in the time period when not in the time period they do noting.
Thanks! ![]()
Have a look at the demo several things at a time which illustrates how to manage timing using millis().
Basically you need to save the value of millis() when the first button is pressed and then take account of other readings until the difference between the saved value and the current value of millis() exceeds 10 seconds - or whatever period you want.
You may also find some useful stuff in planning and implementing a program.
...R
I will sure look at that when i have more time but now i do not have time to learn alot i am sure making progress with arduino everyday and i would be very excited to make these setches myself but i have just not progressed enough now ![]()
Try this.
const byte buttonPin = 2;
unsigned long prevTime = 0;
byte seconds = 0;
void setup()
{
// put your setup code here, to run once:
pinMode(buttonPin, INPUT_PULLUP);
Serial.begin(115200);
}
void loop()
{
// put your main code here, to run repeatedly:
if (digitalRead(buttonPin) == LOW) // if the button was pressed ie brought to GND, go in
{
prevTime = micros(); // get the current time in microseconds
seconds = 10; // reset seconds to 10
}
if (seconds != 0) // keep checking until cycle == 0
{
if (micros() - prevTime >= 1000000UL) // 1 second timer
{
prevTime += 1000000UL; // increment prevTime by the interval of 1 second (1000000 microseconds)
seconds--;
}
//=======================================
// Get readings from sensors etc. here
//=======================================
}
} // End of loop()