#include <stdlib.h>
-#define DATA1_PIN 12
-#define DATA2_PIN 5
-#define DATA3_PIN 4
-#define DATA4_PIN 13
-#define LATCH0_PIN 11
-#define LATCH1_PIN 9
-#define LATCH2_PIN 8
-#define LATCH3_PIN 7
-#define LATCH4_PIN 6
+#define DATA1_PIN 8
+#define DATA2_PIN 9
+#define DATA3_PIN 10
+#define DATA4_PIN 11
+#define LATCH0_PIN 12
+#define LATCH1_PIN 13
+#define LATCH2_PIN 7
+#define LATCH3_PIN 5
+#define LATCH4_PIN 4
#define LATCH5_PIN A5
-#define BLANKING_PIN 10
+#define BLANKING_PIN 6
#define BUTTON_PIN 3
#define POT_PIN A4
void setup()
{
- Serial.begin(9600);
-
pinMode(NC_PIN, INPUT);
- srand(analogRead(NC_PIN));
-
+ uint16_t seed = analogRead(NC_PIN);
+ Serial.begin(9600);
+ Serial.print("PRNG seed: ");
+ Serial.println(seed);
+ srandom(seed);
+
for (uint8_t i = 0; i < 4; i++)
{
- pinMode(data_pins[i], OUTPUT);
digitalWrite(data_pins[i], LOW);
+ pinMode(data_pins[i], OUTPUT);
}
for (uint8_t i = 0; i < DIGITS; i++)
{
- pinMode(latch_pins[i], OUTPUT);
digitalWrite(latch_pins[i], HIGH);
+ pinMode(latch_pins[i], OUTPUT);
}
pinMode(BUTTON_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), button_ISR, FALLING);
pinMode(BLANKING_PIN, OUTPUT);
- digitalWrite(BLANKING_PIN, HIGH);
+ analogWrite(BLANKING_PIN, BRIGHTNESS);
}
void loop()
{
print_7segm(current_value);
- delay(100);
+ delay(10);
}
void button_ISR(void)
{
- current_value = rand();
- current_value |= ((uint32_t) rand() << 16);
+ current_value = random();
+ current_value |= ((uint32_t) random() << 16);
Serial.print(current_value);
}
digit = val % 10;
val /= 10;
+ /*
for (j = 0; j < 4; j++)
{
digitalWrite(data_pins[j], digit & (1 << j));
}
+ */
+ PORTB = (PORTB & 0xF0) | digit;
+
digitalWrite(latch_pins[DIGITS - i - 1], LOW);
- delay(1);
+ delayMicroseconds(1);
digitalWrite(latch_pins[DIGITS - i - 1], HIGH);
- delay(1);
+ delayMicroseconds(1);
}
-}
+}
\ No newline at end of file