Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
83 lines (70 loc) · 1.66 KB
/
Copy pathmain.cpp
File metadata and controls
83 lines (70 loc) · 1.66 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <avr/io.h>
#include "ADC.h"
#include "timer.h"
#include "PWM.h"
#include <Arduino.h>
#include "switch.h"
//Create statemachine for button debouncing
//When system is on motor will rotate based on potentiometer location
//System turns off when button is pushed
// Create states for the debounce machine.
typedef enum stateType_enum{wait_press, dbpress, waitrelse, dbrelse} stateType;
volatile stateType state = wait_press;
int main()
{
Serial.begin(9600);
int valueADC = 0;
double voltage = 0.0;
bool onOff = true;
initTimer0();
initADC();
initPWM();
initSwitchPD0();
sei();
while(1)
{
valueADC = ADCL;
valueADC +=( (unsigned int) ADCH<< 8);
//voltage = valueADC*(5.0/1024.0);
//SetMOTORspeed(valueADC);
/////////////////////////////////////////////////////debounce state machine
switch(state){
case wait_press:
break;
case dbpress:
delayMs(1);
state = waitrelse;
break;
case waitrelse:
break;
case dbrelse:
delayMs(1);
state = wait_press;
switch(onOff){
case false:
onOff = true;
break;
case true:
onOff = false;
break;
}
break;
}
if(onOff){
valueADC = 550;
}
SetMOTORspeed(valueADC);
// Serial.println(voltage);
// Serial.flush();
}
return 0;
}
// Establish ISR using external interput on PORTD
ISR(INT0_vect){
if(state == wait_press){//code to change state based on current state
state = dbpress;
}
if(state == waitrelse){
state = dbrelse;
}
}