Increasement with ONE on keypress

Hey everyone. I’ve founded this code online I’m reworking it, so I come to my needs but now I’ve hit a bump. This is only a section of my code, so I don’t know if this enough to have this work.

In the original code int pointsPerRevolution is 720, but I want it that it starts as for example 10 and every time key is pressed it would be increment with 50. I founded some else his code and tried to implement it, but no success.

Can someone help me with this? It would be a huge help for my project. If you want to see the whole code let me know. (its 712 lines long, so not needed if this can help me).

//int pointsPerRevolution = 720; 
int pointsPerRevolution;

int count = 0; //counter

void randomRevolution() {
  //pointsPerRevolution = random(10, 720);
  pointsPerRevolution = 10;
  iterate = true;

void counterUp() {
  if ( key == CODED ) {
    if (keyCode == CONTROL ) {
  if (count>10) {

1 Like
int pointsPerRevolution = 10;

void keyPressed() {
   if (keyCode == UP) {
   } else if (keyCode == DOWN) {
1 Like

Thanks! It worked! Can I increase with 10 or 50 at a time instead of 1? And how do I stop at certain point?

You can use :

a++; //increments by 1
a += b //increments by b, also works with -=, /=, *= and maybe some others like %=, though i never tried that one...
a = a + b; // the most Basic way. 

And you can make it stop by not pressing the key anymore?

Edit :

Nvm, you meant at a certain value to not increase anymore, right? In that case you can use either constrain.

a += 10;
a = constrain(a, 0, 100); // a will be set to the closest if it’s smaller than 0 or higher than 100

a = constrain(a + 10, 0, 100); // same, just in one line. 

Or you can use an if statement before increasing it.

if (a < 100) {
//this won’t work with variable increments
// for that you‘ll Have to use

if (a <= 100 - b) {
a += b;
1 Like

Alright, that also works, so thanks.
And yeah it stops indeed by not pressing the key. But in my code I start that after 700 nothing else changes any more. (the pointsPerRevolution is var for points in a shape. After 700 points the shape doesn’t change visually a lot any more. So after 700 would be pointless to add. You get it?

1 Like

Yeah, noticed that a bit late :sweat_smile:

Ooh, awesome! That was just what I wanted. You were a great help! You saved my project!

1 Like