Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.72 KB | None | 0 0
  1. void loop() {
  2.   int Voltage = analogRead(1);
  3.   Serial.println(Voltage);
  4.   int yellowzone = (range - minrange) / 100 * 50 + minrange;
  5.   int redzone = (range - minrange) / 100 * 75 + minrange;
  6.   aState = digitalRead(outputA);
  7.   COMPARE VALUES BETWEEN LAST AND CURRENT STATE
  8.   if (aState != aLastState){
  9.     if (digitalRead(outputB) != aState) {
  10.       if(range<maxrange) {
  11.         range+=10;      
  12.       }
  13.     } else {
  14.       if(range>minrange) {
  15.         range-=10;
  16.       }
  17.     }
  18.   }
  19.   aLastState = aState;
  20.   int RedPWM = map(Voltage, minrange, range, 0, 255);
  21.   int GreenPWM = map(Voltage, minrange, range, 50, 0);
  22.   int DB = map(Voltage, minrange, range, 0, 99);
  23.   if (RedPWM < 0) {
  24.     RedPWM = 0;
  25.   }
  26.   if (GreenPWM < 5) {
  27.     GreenPWM = 0;
  28.   }
  29.   if (Voltage > redzone) {
  30.     if (penalty == false) {
  31.       penaltypoints += 10;
  32.       penalty = true;
  33.     }
  34.   }
  35.   else if (Voltage > yellowzone) {
  36.   }
  37.   else {
  38.     if (penalty == true) {
  39.       penalty = false;
  40.     }
  41.     timer++;
  42.   }
  43.   points = timer / 200 - penaltypoints;
  44.   if (points < -1) {
  45.     points = 0;
  46.     timer = 0;
  47.     penaltypoints = 0;
  48.   }
  49.   lcd.setCursor(8, 0);
  50.   lcd.print(points);
  51.   lcd.print("    ");
  52.   lcd.setCursor(0, 3);
  53.   lcd.print(map(range, minrange, maxrange, 0, 100));
  54.   lcd.print("%  ");
  55.   getamountlights(Voltage);
  56.   digitalWrite(latchPin, LOW);
  57.   shiftOut(dataPin, clockPin, MSBFIRST, binget(8 * 4));
  58.   shiftOut(dataPin, clockPin, MSBFIRST,  binget(8 * 3));
  59.   shiftOut(dataPin, clockPin, MSBFIRST, binget(8 * 2));
  60.   shiftOut(dataPin, clockPin, MSBFIRST , binget(8));
  61.   shiftOut(dataPin, clockPin, MSBFIRST,  binget(0));
  62.   digitalWrite(latchPin,
  63.   HIGH);
  64.   analogWrite(redPin, RedPWM);
  65.   analogWrite(greenPin, GreenPWM);
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement