Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. const int numPins = 16;
  7. const bool input = false;
  8. const bool output = true;
  9. const bool high = true;
  10. const bool low = false;
  11.  
  12. vector<bool> pinValue(numPins, false);
  13. vector<bool> pinDirection(numPins, false);
  14.  
  15. void digitalWrite (int pinNumber, bool value) {
  16.     if (pinDirection[pinNumber] == output) {
  17.         pinValue[pinNumber] = value;
  18.     }
  19. }
  20.  
  21. bool digitalRead (int pinNumber) {
  22.     if (pinDirection[pinNumber] == input){
  23.         return pinValue[pinNumber];
  24.     }
  25.     return false;
  26. }
  27.  
  28. void pinMode (int pinNumber, bool mode) {
  29.     pinDirection[pinNumber] = mode;
  30. }
  31.  
  32. void printPinValue (){
  33.     cout << "Pin: ";
  34.     for (int i=0; i<numPins; i++) {
  35.         cout << i;
  36.         if (pinValue[i] == high){
  37.             cout << ":H, ";
  38.         } else {
  39.             cout << ":L, ";
  40.         }
  41.     }
  42.     cout << endl;
  43. }
  44.  
  45. void setup() {
  46. }
  47.  
  48. void loop () {
  49. }
  50.  
  51. int main () {
  52.     printPinValue();
  53.  
  54.     setup();
  55.     while(true){
  56.        loop();
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement