Advertisement
phreaknes

Digital pot Lincoln

Apr 10th, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.57 KB | None | 0 0
  1.  
  2. int CS = 6; // Digipot chip select pin
  3. int UD = 4; // Digipot up / down
  4. int INC = 5; //Digipot increments
  5. int parkPin = 11; //park button
  6. int drivePin = 10; // drive button
  7. int val = 0;
  8. const int ledPinDrive =  8; // Testing LED's
  9. const int ledPinPark = 7; // Testing LED's
  10. const int sensorPin = A0; // wiper pin on Digipot
  11. const int thresholdDrive = 150; // testing threshold
  12. const int thresholdPark = 40; // testing threshold
  13. int buttonState1 = 0;
  14. int buttonState2 = 0;
  15.  
  16. int sensorMin = 1023;
  17. int sensorMax = 0;
  18. int sensorDriveValue = 150;  // testing threshold
  19. int sensorParkValue = 40; // testing threshold
  20.  
  21. void setup() {
  22.   // put your setup code here, to run once:
  23.   pinMode(CS, OUTPUT);
  24.   pinMode(UD, OUTPUT);
  25.   pinMode(INC, OUTPUT);
  26.   pinMode(parkPin, INPUT);
  27.   pinMode(drivePin, INPUT);
  28.   pinMode(ledPinDrive, OUTPUT);
  29.   pinMode(ledPinPark, OUTPUT);
  30.   digitalWrite(CS, HIGH);
  31.   digitalWrite(UD, HIGH);
  32.   digitalWrite(INC, HIGH);
  33.  
  34. }
  35.  
  36. void loop() {
  37.   // put your main code here, to run repeatedly:
  38.   {
  39.     int buttonState1 = digitalRead(parkPin); // Button setup
  40.     int buttonState2 = digitalRead(drivePin);// Button setup
  41.     int analogvalue = analogRead(sensorPin); // setup to Read A0
  42.     val = analogRead(sensorPin); // value of A0
  43.     Serial.println(val); //AO in serial monitor
  44.     delay(5);
  45.  
  46.   }
  47.   // val = digitalRead(drivePin); // establishing pin
  48.   while (digitalRead(parkPin) == HIGH) { // when park button is pushed, sketch goes park void.
  49.     Park();
  50.   }
  51.  
  52.   while (digitalRead(drivePin) == HIGH) { // when drive button is pushed, sketch goes drive void.
  53.     Drive();
  54.   }
  55.  
  56.  
  57. }
  58.  
  59. void Drive() {
  60.   int analogvalue = analogRead(sensorPin);
  61.       digitalWrite(CS, LOW); //This is what is needed to adjust
  62.       digitalWrite(UD, HIGH); //the Digitpot
  63.   if (analogvalue >= sensorDriveValue) {
  64.     digitalWrite(ledPinDrive, HIGH);
  65. //      digitalWrite(CS, LOW); //This is what is needed to adjust
  66. //      digitalWrite(UD, HIGH); //the Digitpot
  67.       digitalWrite(INC, HIGH); //execute in this order
  68.  
  69.   } else {
  70.     digitalWrite(ledPinDrive, LOW); // should do nothing
  71.   }
  72.  
  73. }
  74.  
  75. void Park() {
  76.   int analogvalue = analogRead(sensorPin);
  77.  
  78.   if (analogvalue >= sensorParkValue) {
  79.     digitalWrite(ledPinPark, HIGH);
  80.     //  digitalWrite(CS, LOW); //This is what is needed to adjust
  81.     //  digitalWrite(UD, LOW); //the Digitpot
  82.     //  digitalWrite(INC, HIGH); //execute in this order
  83.  
  84.   } else {
  85.     digitalWrite(ledPinPark, LOW); // should do nothing
  86.   }
  87.  
  88. }
  89.  
  90. // // if (sensorParkValue <= sensorMax && sensorParkValue >= sensorMin){
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement