skizziks_53

Reddit basic coding help v1.0

Sep 3rd, 2020 (edited)
1,971
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. /*
  2.    September 3, 2020
  3.    Reddit basic c/c++ coding...
  4.  
  5. */
  6.  
  7. void setup() {
  8.   // pinMode (2, INPUT); -----------------------> this is not correct, and won't work.
  9.   // You cannot have a space after the keyword "pinmode".
  10.   // The line below shows the correct way.
  11.   pinMode(2, INPUT);
  12.   pinMode(3, INPUT);
  13.   pinMode(4, INPUT);
  14.   pinMode(5, INPUT);
  15.   digitalWrite(2, LOW);
  16.   digitalWrite(3, LOW);
  17.   digitalWrite(4, LOW);
  18.   digitalWrite(5, LOW);
  19.  
  20. }
  21.  
  22. void loop()
  23. {
  24.   // if (digitalRead(2||3) = HIGH) ----------------> this is not correct, and won't work.
  25.   // You can't evaluate two conditions this way because the digitalRead() command does not accept two arguments.
  26.   // Also a comparison requires double equal signs ( == ). The single equals sign is for value assignment ( = ).
  27.   // The line below shows the correct way.
  28.   if ((digitalRead(2) == HIGH) || (digitalRead(3) == HIGH))
  29.   {
  30.     // digitalWrite(4 and 5 = HIGH); --------------> this is not correct, and won't work.
  31.     // The digitalWrite() command only accepts two arguments, the pin number and the value to write.
  32.     // The two lines below show the correct way.
  33.     digitalWrite(4, HIGH);
  34.     digitalWrite(5, HIGH);
  35.     delay(1000);
  36.     digitalWrite(4, LOW);
  37.     digitalWrite(5, LOW);
  38.   }
  39.  
  40.   else {
  41.     digitalWrite(4, LOW);
  42.     digitalWrite(5, LOW);
  43.   }
  44. }
  45.  
  46. // the end
Advertisement
Add Comment
Please, Sign In to add comment