Hello guys!
Im stuck with this very simple task:
"Measure whether a button (pin(x)) is pressed or not (10 times / sec) and save the value in an array of 10 values."
Any help and guidence would be much appriciated
Processing: HELP.ino...
Hello guys!
Im stuck with this very simple task:
"Measure whether a button (pin(x)) is pressed or not (10 times / sec) and save the value in an array of 10 values."
Any help and guidence would be much appriciated
Processing: HELP.ino...
When is our assignment due ?
What have you tried so far ?
Heres my code! Knapp = button in swedish
int knapp[10];
int knapptryck=0;
int i=0;
void setup() {
// put your setup code here, to run once:
pinMode(4,INPUT);
pinMode(13,OUTPUT);
Serial.begin(115200);
}
void loop() {
knapptryck=digitalRead(4);
if (knapptryck==HIGH){
for(int i=0;i>99;i++)
{
}
digitalWrite(13,HIGH);
}
else{
digitalWrite(13,LOW);
}
delay(1);
}
// put your main code here, to run repeatedly:
Did you try to attach your code (wrong), provide a link to it (wrong) or Auto Format it in the IDE, select "Copy for Forum" from the IDE right click menu and paste it here (correct) ?
Please follow the advice given in the link below when posting code. Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination
I’m not sure, but your requirements are a bit fuzzy!
How are you going to press a button ten times per second ?
What value gets stored in which index of the array ?
Yes it is very fuzzy, the quote is literally all we got told to do by our Teacher.
It should measure whenever the button is pressed or not, it does this 10 times during a second. I think the values that are being saved in the array should be ones and zeros: 1 if the buttom is pressed, 0 if not.
Yeah, that's how I read it as well. Very odd, and it doesn't match with any real-world problem you'd run into.
Even in this interpretation something is missing: for how many seconds should the sketch record this information?
for infinity i guess?
No computer system has infinite memory. So that can't be a realistic requirement.
You know what would be great? We get people on here daily who need to do an assignment for school. More often than not, the requirements are poorly formulated, incomplete or ambivalent. What we never get, is teachers reporting here with the question "I'm thinking of this or that assignment, this aspect is what I want my students to learn - can you give feedback on how I formulated it?" It would be so awesome if that also started happening.
Sorry to go off topic. I just think your teacher needs to go back to school.
I read this as "every 0.1 of a second for one second read the button state and save that state in an array of 10 values"
Whether such is a useful thing to do is not the point. Such an exercise would show the use of non blocking timing, taking action at intervals during a fixed timing period and the use of an array to save readings
A future exercise could be to analyse the readings in the array for some purpose and to replace the with a higher frequency input
Would it? AFAIK it would work fine with a delay(100)...
You are correct. My mind naturally led me to the use of millis() as that is what I would use.
Maybe the idea is to lead the students to the easy to use delay() function only to dash their dreams by introducing a requirement that requires non blocking code
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.