Advertisement
offchristianamr

Untitled

Nov 27th, 2021
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. // C++ code
  2. //
  3.  
  4. const int potPin = A0;
  5. const int pwmPin1 = 3;
  6. const int pwmPin2 = 5;
  7. const int pwmPin3 = 6;
  8. int digitalPinsInUse [] = {3,5,6};
  9. int i;
  10.  
  11. void setup()
  12. {
  13.   pinMode(potPin, INPUT);
  14.   pinMode (pwmPin1, OUTPUT);
  15.   pinMode (pwmPin2, OUTPUT);
  16.   pinMode (pwmPin3, OUTPUT);
  17.   Serial.begin(9600);
  18. }
  19.  
  20. int potLight(int highPin) {
  21.   for (i = 0; i < 3; ++i) {
  22.     if (digitalPinsInUse[i] == highPin) {
  23.       digitalWrite(digitalPinsInUse[i], HIGH);
  24.       Serial.print("Pin ");
  25.       Serial.print(digitalPinsInUse[i]);  
  26.       Serial.println(" HIGH");
  27.     }
  28.     else {
  29.       digitalWrite(digitalPinsInUse[i], LOW);
  30.     }
  31.   }
  32. }
  33.  
  34. void loop()
  35. {
  36.   int potAmount = analogRead(potPin);
  37.     //Serial.println(potAmount);
  38.   if (potAmount < 341) {
  39.     potLight(pwmPin1);
  40.   }
  41.   else if (potAmount < 682) {
  42.     potLight(pwmPin2);
  43.   }
  44.   else if (potAmount <= 1023) {
  45.     potLight(pwmPin3);
  46.   }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement