Hiii
I am a very new in arduino and need help for coding simple program
- I need code to add value by pressing on button every time increase by one until reach value of 15 and then reset it self to be 0 again
can any one help me,,,,
Thanks
Hiii
I am a very new in arduino and need help for coding simple program
Hi MahmoudEzz and welcome to the forum.
The goal of the forum is help users/posters by providing pointers, links or hints, so that the person can put the code together using suggested methods or approach, which learning Arduino / C++ at the same time.
If we were to provide an already chewed up code which works right away, and you have done nothing in the process, you haven't learned much.
Have you built your circuit with the switch/button ?
Have you played around with the several which are included with the IDE ?
(like Blink ?).
Here is a link to a sketch that might be of help.
In order to read the switch, you will need to get acquainted with DigitalRead
Here is a link that provides insight to the DigitalRead command.
Once you have read the status of the switch, you will need to determine whether it is open or close ,
This might require an IF statement...
daniel
i hope it helps.
Have you looked at the example programs that come with the Arduino IDE? One of them will probably be very close to what you need.
Then try modifying it. And if it does not work post your code here and we will try to help.
If you just want someone else to write a program for you ask in the Gigs and Collaborations section and be prepared to pay.
...R
MahmoudEzz:
I am a very new in arduino and need help for coding simple program
- I need code to add value by pressing on button every time increase by one until reach value of 15 and then reset it self to be 0 again
can any one help me,,,,
Reset from 14 to 0 after button pressed next time?
Or reset from 15 to 0 after button pressed next time?
Programming example (connect button pins to GND and the pin number defined):
const byte BUTTONPIN=A3;
boolean buttonPressed() // returns true if button has been pressed
{
static byte oldState;
static unsigned long lastMillis;
long now = millis();
if (now - lastMillis < 10) return false; // debounce with 10 milliseconds
lastMillis = now;
byte state = digitalRead(BUTTONPIN);
if (state != oldState)
{
oldState = state;
if (state == LOW) return true;
}
return false;
}
void setup() {
Serial.begin(9600); // Prepare Serial for output at 9600 Baud
Serial.println("Good night and good luck!");
pinMode(BUTTONPIN, INPUT_PULLUP);
}
byte pressCount=0;
void loop() {
if (buttonPressed())
{
pressCount= (pressCount+1)%15; // Count from 0...14 and reset with next button pressed
Serial.println(pressCount);
}
}
Output is sent to the serial monitor.
Thanks dsauriol & Robin2
I really thankful for your replay,
but i am really new in programming language at all.
and in fact i try the examples in adruino IDE like Blink and Button after that i ask for help and i cant do it.
Second thing, i know that i supposed to try harder before i ask here.
Thanks again dsauriol & Robin2 for advice.
There are all kinds of tutorials on Arduino C programming on the web, many are free. Read those until some of the sample programs start to make sense.
The state change detection example does exactly what you want. It counts every time a switch becomes pressed. The only way that your requirement differs is that you want to reset to 0 when the counter gets to 15, which is easily handled by an if statement.
Is it to late to change what subject you are studying? Computing obviously doesn't interest you at all.
PaulMurrayCbr:
Is it to late to change what subject you are studying? Computing obviously doesn't interest you at all.
maybe it is just a mandatory introduction semester in another study