Score - JuliaElizabethLittle/peeMarksmanship GitHub Wiki

###SCORE

So to start off we started with the calculation. As we said, the rain sensors weren't working correctly so we were using a POT sensor. So basically we want to read the value the sensor is giving you (a value between 0 and 1023) and map it so the value is between 0 and 10. Then if this value is above 0 we want to add it to the score. Because it is read by sensor A we want it to be times 20. To make sure it was all happening correctly we printed everything out on our Serial print. If the value vas zero we also wanted to know, so it would print that the sensor wasn't receiving any values. We can see below how we did it:

sensorA = analogRead (A0);
sensorA = map(sensorA,0,1023,0,10);

Serial.println("SENSOR A: ");
Serial.println(sensorA);

if (sensorA > 0){
  score = sensorA*20;
  Serial.println("Score + A: ");
  Serial.println(score);
}else{
  Serial.println("NO SENSOR A");
}
delay(5);

Since it worked we did the Same for sensorB and SensorC. With the difference, that each time a new sensor was read the value was added to the variable score:


sensorB = analogRead (A1);
sensorB = map(sensorB,0,1023,0,10);

Serial.println("SENSOR B: ");
Serial.println(sensorB);

if (sensorB > 0){
  score = score + sensorB*10;
  Serial.println("Score + A + B: ");
  Serial.println(score);
}else{
  Serial.println("NO SENSOR B");
}
delay(5);


sensorC = analogRead (A2);
sensorC = map(sensorC,0,1023,0,10);

Serial.println("SENSOR C: ");
Serial.println(sensorC);

if (sensorC > 0){
  score = score + sensorC*5;
  Serial.println("Score + A + B + C: ");
  Serial.println(score);
}else{
  Serial.println("NO SENSOR C");
}

delay(5);

So at the end, the final value of score is the added value of all the sensors (multiplied by their scoring).

###CHAIN

So when do the problems come? Well, when we decide that we only want the value of score when we press a pushbutton (that would be our chain).

The idea was that the variable chain went in function of the button ( = 2 ) when LOW (it usually is set al high) printed the score, and reset the marker to 0. And we wrote it the following way:

chain = digitalRead(button);
//Serial.println(chain);

if(chain == LOW){
    Serial.println(score);
    score = 0;
}

Adding High Score was the next step!