user39090: int val1 = 0;
byte val2 = 10;
int buttonPin = A0;
byte result = 0;

void setup() {
    Serial.begin(115200);
}

void loop() {
    val1 = digitalRead(buttonPin);

    if (buttonPin == HIGH) {
        result = result + val2;
        result = result + 10;
    } 
    else
    {
        digitalWrite(val1, LOW);
    }

    Serial.print("STATE   ");
    Serial.print(val1);
    Serial.print("    ");
    Serial.print(result);
    Serial.println();

    delay(100);
}


user61788: I appears you want to increment the result by val2 each time the button is pressed.  If you want to wire it up this way you can but there are potential issues with this, such as not catching each time you press the button, or thinking you pressed the button twice when you accidentally held it down for more than 100ms.  The code for this method is below:
const int buttonPin = A0;
bool buttonState = LOW;
int val = 10;
int result = 0;

void setup()
{
  pinMode(buttonPin,INPUT);
  Serial.begin(115200);
}

void loop()
{
    buttonState = digitalRead(buttonPin);

    if (buttonState == HIGH)
    {
        result = result + val;
    } 

    Serial.print("STATE:   ");
    Serial.print(buttonState);
    Serial.print("\t");
    Serial.print("RESULT:  ");
    Serial.print(result);
    Serial.println();

    delay(100);
}

The way to prevent double counts or missing counts would be to use interrupts.  Later I may write that one up if you need that instead.
Good Luck!

39090: <pre><code>int val1 = 0;
byte val2 = 10;
int buttonPin = A0;
byte result = 0;

void setup() {
    Serial.begin(115200);
}

void loop() {
    val1 = digitalRead(buttonPin);

    if (buttonPin == HIGH) {
        result = result + val2;
        result = result + 10;
    } 
    else
    {
        digitalWrite(val1, LOW);
    }

    Serial.print("STATE   ");
    Serial.print(val1);
    Serial.print("    ");
    Serial.print(result);
    Serial.println();

    delay(100);
}
</code></pre>
 61788: <p>I appears you want to increment the result by val2 each time the button is pressed.  If you want to wire it up this way you can but there are potential issues with this, such as not catching each time you press the button, or thinking you pressed the button twice when you accidentally held it down for more than 100ms.  The code for this method is below:</p>

<pre><code>const int buttonPin = A0;
bool buttonState = LOW;
int val = 10;
int result = 0;

void setup()
{
  pinMode(buttonPin,INPUT);
  Serial.begin(115200);
}

void loop()
{
    buttonState = digitalRead(buttonPin);

    if (buttonState == HIGH)
    {
        result = result + val;
    } 

    Serial.print("STATE:   ");
    Serial.print(buttonState);
    Serial.print("\t");
    Serial.print("RESULT:  ");
    Serial.print(result);
    Serial.println();

    delay(100);
}
</code></pre>

<p>The way to prevent double counts or missing counts would be to use interrupts.  Later I may write that one up if you need that instead.</p>

<p>Good Luck!</p>
