 const int SEGMENT_F_PIN = 7;
 const int SEGMENT_G_PIN = 13;
 
+const byte DIGIT_OFF = 255;
+const byte DIGIT_ON = 10; // increase the value to reduce current
+
+const short MINUS = -1;
+const short DEGREE = -2;
+
+int currentDigitIndex = 0;
+short digits[4];
+
+void activateDigit(int digit) {
+  switch (digit) {
+    case 0:
+      analogWrite(DIGIT_1_PIN, DIGIT_ON);
+      analogWrite(DIGIT_2_PIN, DIGIT_OFF);
+      analogWrite(DIGIT_3_PIN, DIGIT_OFF);
+      analogWrite(DIGIT_4_PIN, DIGIT_OFF);
+      break;
+    case 1:
+      analogWrite(DIGIT_1_PIN, DIGIT_OFF);
+      analogWrite(DIGIT_2_PIN, DIGIT_ON);
+      analogWrite(DIGIT_3_PIN, DIGIT_OFF);
+      analogWrite(DIGIT_4_PIN, DIGIT_OFF);
+      break;
+    case 2:
+      analogWrite(DIGIT_1_PIN, DIGIT_OFF);
+      analogWrite(DIGIT_2_PIN, DIGIT_OFF);
+      analogWrite(DIGIT_3_PIN, DIGIT_ON);
+      analogWrite(DIGIT_4_PIN, DIGIT_OFF);
+      break;
+    case 3:
+      analogWrite(DIGIT_1_PIN, DIGIT_OFF);
+      analogWrite(DIGIT_2_PIN, DIGIT_OFF);
+      analogWrite(DIGIT_3_PIN, DIGIT_OFF);
+      analogWrite(DIGIT_4_PIN, DIGIT_ON);
+      break;
+    default:
+      analogWrite(DIGIT_1_PIN, DIGIT_OFF);
+      analogWrite(DIGIT_2_PIN, DIGIT_OFF);
+      analogWrite(DIGIT_3_PIN, DIGIT_OFF);
+      analogWrite(DIGIT_4_PIN, DIGIT_OFF);
+  }    
+}
+
+void drawDigit(short value) {
+  switch (value) {
+    case DEGREE:
+      digitalWrite(SEGMENT_A_PIN, HIGH);
+      digitalWrite(SEGMENT_B_PIN, HIGH);
+      digitalWrite(SEGMENT_C_PIN, LOW);
+      digitalWrite(SEGMENT_D_PIN, LOW);
+      digitalWrite(SEGMENT_E_PIN, LOW);
+      digitalWrite(SEGMENT_F_PIN, HIGH);
+      digitalWrite(SEGMENT_G_PIN, HIGH);
+      break;
+    case MINUS:
+      digitalWrite(SEGMENT_A_PIN, LOW);
+      digitalWrite(SEGMENT_B_PIN, LOW);
+      digitalWrite(SEGMENT_C_PIN, LOW);
+      digitalWrite(SEGMENT_D_PIN, LOW);
+      digitalWrite(SEGMENT_E_PIN, LOW);
+      digitalWrite(SEGMENT_F_PIN, LOW);
+      digitalWrite(SEGMENT_G_PIN, HIGH);
+      break;
+    case 0:
+      digitalWrite(SEGMENT_A_PIN, HIGH);
+      digitalWrite(SEGMENT_B_PIN, HIGH);
+      digitalWrite(SEGMENT_C_PIN, HIGH);
+      digitalWrite(SEGMENT_D_PIN, HIGH);
+      digitalWrite(SEGMENT_E_PIN, HIGH);
+      digitalWrite(SEGMENT_F_PIN, HIGH);
+      digitalWrite(SEGMENT_G_PIN, LOW);
+      break;
+    case 1:
+      digitalWrite(SEGMENT_A_PIN, LOW);
+      digitalWrite(SEGMENT_B_PIN, HIGH);
+      digitalWrite(SEGMENT_C_PIN, HIGH);
+      digitalWrite(SEGMENT_D_PIN, LOW);
+      digitalWrite(SEGMENT_E_PIN, LOW);
+      digitalWrite(SEGMENT_F_PIN, LOW);
+      digitalWrite(SEGMENT_G_PIN, LOW);
+      break;
+    case 2:
+      digitalWrite(SEGMENT_A_PIN, HIGH);
+      digitalWrite(SEGMENT_B_PIN, HIGH);
+      digitalWrite(SEGMENT_C_PIN, LOW);
+      digitalWrite(SEGMENT_D_PIN, HIGH);
+      digitalWrite(SEGMENT_E_PIN, HIGH);
+      digitalWrite(SEGMENT_F_PIN, LOW);
+      digitalWrite(SEGMENT_G_PIN, HIGH);
+      break;
+    case 3:
+      digitalWrite(SEGMENT_A_PIN, HIGH);
+      digitalWrite(SEGMENT_B_PIN, HIGH);
+      digitalWrite(SEGMENT_C_PIN, HIGH);
+      digitalWrite(SEGMENT_D_PIN, HIGH);
+      digitalWrite(SEGMENT_E_PIN, LOW);
+      digitalWrite(SEGMENT_F_PIN, LOW);
+      digitalWrite(SEGMENT_G_PIN, HIGH);
+      break;
+    case 4:
+      digitalWrite(SEGMENT_A_PIN, LOW);
+      digitalWrite(SEGMENT_B_PIN, HIGH);
+      digitalWrite(SEGMENT_C_PIN, HIGH);
+      digitalWrite(SEGMENT_D_PIN, LOW);
+      digitalWrite(SEGMENT_E_PIN, LOW);
+      digitalWrite(SEGMENT_F_PIN, HIGH);
+      digitalWrite(SEGMENT_G_PIN, HIGH);
+      break;
+    case 5:
+      digitalWrite(SEGMENT_A_PIN, HIGH);
+      digitalWrite(SEGMENT_B_PIN, LOW);
+      digitalWrite(SEGMENT_C_PIN, HIGH);
+      digitalWrite(SEGMENT_D_PIN, HIGH);
+      digitalWrite(SEGMENT_E_PIN, LOW);
+      digitalWrite(SEGMENT_F_PIN, HIGH);
+      digitalWrite(SEGMENT_G_PIN, HIGH);
+      break;
+    case 6:
+      digitalWrite(SEGMENT_A_PIN, HIGH);
+      digitalWrite(SEGMENT_B_PIN, LOW);
+      digitalWrite(SEGMENT_C_PIN, HIGH);
+      digitalWrite(SEGMENT_D_PIN, HIGH);
+      digitalWrite(SEGMENT_E_PIN, HIGH);
+      digitalWrite(SEGMENT_F_PIN, HIGH);
+      digitalWrite(SEGMENT_G_PIN, HIGH);
+      break;
+    case 7:
+      digitalWrite(SEGMENT_A_PIN, HIGH);
+      digitalWrite(SEGMENT_B_PIN, HIGH);
+      digitalWrite(SEGMENT_C_PIN, HIGH);
+      digitalWrite(SEGMENT_D_PIN, LOW);
+      digitalWrite(SEGMENT_E_PIN, LOW);
+      digitalWrite(SEGMENT_F_PIN, LOW);
+      digitalWrite(SEGMENT_G_PIN, LOW);
+      break;
+    case 8:
+      digitalWrite(SEGMENT_A_PIN, HIGH);
+      digitalWrite(SEGMENT_B_PIN, HIGH);
+      digitalWrite(SEGMENT_C_PIN, HIGH);
+      digitalWrite(SEGMENT_D_PIN, HIGH);
+      digitalWrite(SEGMENT_E_PIN, HIGH);
+      digitalWrite(SEGMENT_F_PIN, HIGH);
+      digitalWrite(SEGMENT_G_PIN, HIGH);
+      break;
+    case 9:
+      digitalWrite(SEGMENT_A_PIN, HIGH);
+      digitalWrite(SEGMENT_B_PIN, HIGH);
+      digitalWrite(SEGMENT_C_PIN, HIGH);
+      digitalWrite(SEGMENT_D_PIN, HIGH);
+      digitalWrite(SEGMENT_E_PIN, LOW);
+      digitalWrite(SEGMENT_F_PIN, HIGH);
+      digitalWrite(SEGMENT_G_PIN, HIGH);
+      break;
+    default:
+      digitalWrite(SEGMENT_A_PIN, LOW);
+      digitalWrite(SEGMENT_B_PIN, LOW);
+      digitalWrite(SEGMENT_C_PIN, LOW);
+      digitalWrite(SEGMENT_D_PIN, LOW);
+      digitalWrite(SEGMENT_E_PIN, LOW);
+      digitalWrite(SEGMENT_F_PIN, LOW);
+      digitalWrite(SEGMENT_G_PIN, LOW);
+  }
+}
+
 void setup() {
   pinMode(DIGIT_1_PIN, OUTPUT);
   pinMode(DIGIT_2_PIN, OUTPUT);

  pinMode(SEGMENT_F_PIN, OUTPUT);
  pinMode(SEGMENT_G_PIN, OUTPUT);
  
  digitalWrite(DIGIT_1_PIN, HIGH);
  digitalWrite(DIGIT_2_PIN, HIGH);
  digitalWrite(DIGIT_3_PIN, HIGH);
  digitalWrite(DIGIT_4_PIN, LOW);
  digitalWrite(SEGMENT_A_PIN, HIGH);
  digitalWrite(SEGMENT_B_PIN, HIGH);
  digitalWrite(SEGMENT_C_PIN, HIGH);

  digitalWrite(SEGMENT_E_PIN, HIGH);
  digitalWrite(SEGMENT_F_PIN, HIGH);
  digitalWrite(SEGMENT_G_PIN, HIGH);
  
  digits[0] = MINUS;
  digits[1] = 2;
  digits[2] = 3;
  digits[3] = DEGREE;
}

void loop() {
  activateDigit(currentDigitIndex);
  drawDigit(digits[currentDigitIndex]);
  
  currentDigitIndex++;
  if (currentDigitIndex >= 4) currentDigitIndex = 0;
  
  delayMicroseconds(500);
}
