Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * RandomDice.cpp
- *
- * Created: 07.10.2015 18:43:43
- * Author : Kim-Yannick
- */
- #define F_CPU 10000000UL
- #include <avr/io.h>
- #include <util/delay.h>
- #include <stdlib.h>
- char codes[] = {0b01111110, 0b01001000, 0b00111101, 0b01101101, 0b01001011, 0b01100111, 0b01110111};
- int main(void)
- {
- DDRD = 0xFF;
- DDRC = 0x00;
- PORTD = 1 << 7;
- PORTC = 1;
- int seed = 0;
- while (PINC&1) {
- seed += 1;
- _delay_ms(5);
- }
- srand(seed);
- while (1) {
- unsigned int number = rand();
- PORTD |= 1 << 7;
- while (!PINC&1) {
- number = rand();
- _delay_ms(10);
- }
- PORTD = codes[number%6+1];
- while (PINC&1)
- _delay_ms(10);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment