Astranome

STM32 read btns & pots

Nov 5th, 2022
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | Music | 0 0
  1. //Buttons pin number array
  2. byte Btns[16] = {13,12,14,27,26,25,33,32,15,4,16,17,18,19,22,23};
  3.  
  4. //VarPots pin number array
  5. byte Pots[4] = {35, 34, 39, 36};
  6.  
  7. void setup()
  8. {
  9.   Serial.begin (115200);
  10.  
  11.   for (int i = 0; i<16; i++)
  12.   {
  13.     pinMode(Btns[i], INPUT_PULLUP);
  14.   }
  15.  
  16. }
  17.  
  18. void loop()
  19. {
  20.   //VarPots(); //uncomment this line to test the potentiometers
  21.   //Buttons(); //uncomment this line to test the buttons
  22. }
  23.  
  24. void Buttons ()
  25. {
  26.   for (int i = 0; i<16; i++)
  27.   {
  28.     if (digitalRead(Btns[i]) == LOW)
  29.     {
  30.       Serial.print ("Button "); Serial.print (i+1); Serial.println (" ON");
  31.     }
  32.   }
  33. }
  34.  
  35. void VarPots ()
  36. {
  37.   for (int i = 0; i<4; i++)
  38.   {
  39.       Serial.print ("Pot "); Serial.print (i+1);
  40.       Serial.print (" / Value: "); Serial.print(analogRead(Pots[i]));
  41.       Serial.print (" | ");
  42.   }
  43.  
  44.   Serial.println();
  45. }
  46.  
Add Comment
Please, Sign In to add comment