aboutsummaryrefslogtreecommitdiff
path: root/sem4/embedded/m1/int/int.ino
blob: c4a2c31dae6c28f57757d091d79af9845dadbe0b (plain)
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
#define LEDPIN 13
#define BUTTONPIN 2

#define DEBOUNCE 1

ISR(INT0_vect) {
    static unsigned long last = 0;

    unsigned long now = millis();
    if (now - last < 100) {
        return;
    }
    last = now;

	static unsigned char state = 0;

	// Toggle LEDPIN
	digitalWrite(LEDPIN, state % 2 == 0);
	state++;
    Serial.print("Hej "); Serial.println(state);

}

void setup() {

	// We need to talk
	Serial.begin(9600);

	// Setup pinmodes
	pinMode(LEDPIN, OUTPUT);
	pinMode(BUTTONPIN, INPUT_PULLUP);

	// Attach a interrupt on the button
	//attachInterrupt(digitalPinToInterrupt(BUTTONPIN), testy, RISING);
	
	// Enable interrupt 0
	EIMSK |= 1 << INT0;
	// Eable on rising edge
	EICRA |= (1 << ISC01) | (1 << ISC00);

}

void loop() {
	static int i = 0;

	//Serial.print("Cool stuff happening now ");
	//Serial.println(i++);

}