Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void loop() {
- int Voltage = analogRead(1);
- Serial.println(Voltage);
- int yellowzone = (range - minrange) / 100 * 50 + minrange;
- int redzone = (range - minrange) / 100 * 75 + minrange;
- aState = digitalRead(outputA);
- COMPARE VALUES BETWEEN LAST AND CURRENT STATE
- if (aState != aLastState){
- if (digitalRead(outputB) != aState) {
- if(range<maxrange) {
- range+=10;
- }
- } else {
- if(range>minrange) {
- range-=10;
- }
- }
- }
- aLastState = aState;
- int RedPWM = map(Voltage, minrange, range, 0, 255);
- int GreenPWM = map(Voltage, minrange, range, 50, 0);
- int DB = map(Voltage, minrange, range, 0, 99);
- if (RedPWM < 0) {
- RedPWM = 0;
- }
- if (GreenPWM < 5) {
- GreenPWM = 0;
- }
- if (Voltage > redzone) {
- if (penalty == false) {
- penaltypoints += 10;
- penalty = true;
- }
- }
- else if (Voltage > yellowzone) {
- }
- else {
- if (penalty == true) {
- penalty = false;
- }
- timer++;
- }
- points = timer / 200 - penaltypoints;
- if (points < -1) {
- points = 0;
- timer = 0;
- penaltypoints = 0;
- }
- lcd.setCursor(8, 0);
- lcd.print(points);
- lcd.print(" ");
- lcd.setCursor(0, 3);
- lcd.print(map(range, minrange, maxrange, 0, 100));
- lcd.print("% ");
- getamountlights(Voltage);
- digitalWrite(latchPin, LOW);
- shiftOut(dataPin, clockPin, MSBFIRST, binget(8 * 4));
- shiftOut(dataPin, clockPin, MSBFIRST, binget(8 * 3));
- shiftOut(dataPin, clockPin, MSBFIRST, binget(8 * 2));
- shiftOut(dataPin, clockPin, MSBFIRST , binget(8));
- shiftOut(dataPin, clockPin, MSBFIRST, binget(0));
- digitalWrite(latchPin,
- HIGH);
- analogWrite(redPin, RedPWM);
- analogWrite(greenPin, GreenPWM);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement