I have started trying to program the uno, and having trouble understanding the language and the structure. my first question is how do you do more i can see how to do somethings but as an example i need a dbounce which i got working from examples but now i need code to count the button presses and dont understand how to keep adding to the code.
I have bought 3 books but they havent covererd this only very basic stuff
Hope someone can help
One thing you need to learn about the forum is that it is one-way.
We can't see your code unless you show it to us.
Until you do, it is difficult to help.
This may be a jump ahead, but there are lots of different ideas and solutions here: http://arduino.cc/playground/Main/GeneralCodeLibrary
You will learn a lot from reading other people's code.
There are generally three parts in an arduino code.
Anything before the setup are variable declarations that can be used throughout the code and library initialisation.
Than everything in the setup runs once, at the beginning or if you pressed the reset button(that restarts your sketch).
The loop is what we use to make repetitive actions, it runs until you turn the power off.
For example: counting the number of times a button is pressed requires consistent monitoring of the button's state.
This is therefore processed in the loop.
Gives us the code and what you want to do with it so that we can help you.
well its been a slow start, i can program a plc to do everything i want to do with this uno in 15 mins, but the cost of the plc is way to expensive.
here is my first attemps and yes it didnt work. i dont get any error, as you can see i have started with an existing program which works perfectly, accept for my addition
/* SoftwareDebounce
*
- At each transition from LOW to HIGH or from HIGH to LOW
- the input signal is debounced by sampling across
- multiple reads over several milli seconds. The input
- is not considered HIGH or LOW until the input signal
- has been sampled for at least "debounce_count" (10)
- milliseconds in the new state.
-
- Notes:
- Adjust debounce_count to reflect the timescale
- over which the input signal may bounce before
- becoming steady state
-
- Based on:
- http://www.arduino.cc/en/Tutorial/Debounce
-
- Jon Schlueter
- 30 December 2008
-
-
Arduino Playground - SoftwareDebounce
*/
int inPin = 7; // the number of the input pin
int outPin13 = 13; // the number of the output pin
int outPin12 = 12;
int counter = 0; // how many times we have seen new value
int reading; // the current value read from the input pin
int current_state = LOW; // the debounced input value
// the following variable is a long because the time, measured in milliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0; // the last time the output pin was sampled
int debounce_count = 1000; // number of millis/samples to consider before declaring a debounced input
int permanent_on_count = 2000; // number of millis/samples to consider before declaring an input for permanent on
void setup()
{
pinMode(inPin, INPUT);
pinMode(outPin13, OUTPUT);
digitalWrite(outPin13, current_state); // setup the Output LED for initial state
}
void loop()
{
// If we have gone on to the next millisecond
if(millis() != time)
{
reading = digitalRead(inPin);
if(reading == current_state && counter > 0)
{
counter--;
}
if(reading != current_state)
{
counter++;
}
// If the Input has shown the same value for long enough let's switch it
if(counter >= debounce_count)
{
counter = 0;
current_state = reading;
digitalWrite(outPin13, current_state);
}
time = millis();
// If the Input has shown the same value for long enough let's switch it on permenant
if(counter >= permanent_on_count)
{
counter = 0;
current_state = 1;
digitalWrite(outPin12, current_state);
}
time = millis();
}
}
if(millis() != time)
That's going to be most of the time, isn't it?
i have no idea what you are stating since im strugleing with the code as it is. too criptic for me
"!=" translates as "not equal to" unless the main loop is running at least 1000 times a second, it could almost never be anything other than true.