-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTicTacToe.ino
70 lines (56 loc) · 1.25 KB
/
TicTacToe.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include <avr/eeprom.h>
#include <util/atomic.h>
#include "Debug.h"
#include "TicTacToeGame.h"
#define KEYPAD1_BASE 41
#define KEYPAD2_BASE 27
#define SERVO_ELBOW 11
#define SERVO_SHOULDER 12
#define SERVO_BASE 13
TicTacToeGame game;
TicTacToeArm* arm;
Keypad* keypad_primary;
Keypad* keypad_secondary;
LiquidCrystal_I2C* lcd;
volatile uint32_t seed;
volatile int8_t nrot;
void random_seed();
ISR(WDT_vect);
void random_seed() {
seed = 0;
nrot = 32;
cli();
MCUSR = 0;
_WD_CONTROL_REG |= (1<<_WD_CHANGE_BIT) | (1<<WDE);
_WD_CONTROL_REG = (1<<WDIE);
sei();
while (nrot > 0);
cli();
MCUSR = 0;
_WD_CONTROL_REG |= (1<<_WD_CHANGE_BIT) | (0<<WDE);
_WD_CONTROL_REG = (0<< WDIE);
sei();
}
ISR(WDT_vect) {
nrot--;
seed = seed << 8;
seed = seed ^ TCNT1L;
}
void setup() {
random_seed();
randomSeed(seed);
Serial.begin(115200);
lcd = new LiquidCrystal_I2C(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
arm = new TicTacToeArm(SERVO_BASE, SERVO_SHOULDER, SERVO_ELBOW);
keypad_primary = new Keypad(KEYPAD1_BASE);
keypad_secondary = new Keypad(KEYPAD2_BASE);
game.setup(lcd, arm, keypad_primary, keypad_secondary);
}
void loop() {
game.loop();
}