0

raw code:

int buzzer = 11; 
int forcePin1 = A1; 
int forcePin2 = A2; 
int Forcevalue = 0; 

void setup() 
{ 
    pinMode(forcePin1, INPUT); 
    pinMode(forcePin2, INPUT); 
    pinMode(buzzer, OUTPUT); 
    Serial.begin(9600); 
}
void loop() 
{ 
    Forcevalue = analogRead(forcePin1 && forcePin2); 
    Serial.println (Forcevalue); 
    noTone(buzzer); 
    tone(buzzer,Forcevalue); 
}

I don't know why it only cares about forcePin1, I've tried changing the "&&" to "=+" and that made it only care about forcePin2 instead.

If someone could help me make it so either one or both of forcePin1 and forcePin2 needs to be activated for the buzzer to ring, that'd be greatly appreciated

Screenshot of tinkercad: https://gyazo.com/e0332aae51465ee17f8c6d3767f93345

Code on tinkercad: https://gyazo.com/73be78c2bf210dd41b29ca236c57f0c6

user4581301
  • 33,082
  • 7
  • 33
  • 54
Jacob
  • 19
  • 6
  • You need to apply `&&` and/or `+` to the *result* of `analogRead`, not the pin numbers. – nanofarad May 27 '21 at 20:19
  • do you mean like: Forcevalue = analogRead(forcePin1)+(forcePin2); – Jacob May 27 '21 at 20:25
  • No, I mean `analogRead(forcePin1)+analogRead(forcePin2)`. It doesn't make sense to take the reading from force pin 1, and add the *pin number* of pin 2 to it. – nanofarad May 27 '21 at 20:26
  • the problem is that it's only registering the value from forcePin1 when I want it to use both – Jacob May 27 '21 at 20:26
  • thank you so much nanorfarad, you're a hero – Jacob May 27 '21 at 20:27
  • 1
    Side note: It's irrelevant here since you also provided the code as text, but don't post pictures of code. [They are unhelpful to you, us, and those that follow](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question). If you have a question that only provides a picture of code, the question probably won't survive long enough for you to add the code as text. – user4581301 May 27 '21 at 20:31

0 Answers0