rotary works so far
This commit is contained in:
parent
53d707f5ef
commit
d98c3ab3a2
@ -10,11 +10,7 @@
|
||||
|
||||
|
||||
|
||||
<<<<<<< local
|
||||
volatile float U_des = 12.0;
|
||||
=======
|
||||
volatile float u_des = 14.0;
|
||||
>>>>>>> other
|
||||
|
||||
|
||||
|
||||
@ -54,8 +50,10 @@ void cycle() {
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
lcd.begin(LCD_COLS, LCD_ROWS);
|
||||
lcd.print("Teensy SMPS");
|
||||
Serial.println("Teensy SMPS");
|
||||
pinMode(PWM_PIN, OUTPUT);
|
||||
analogWrite(PWM_PIN, PWM_MIN);
|
||||
analogWriteFrequency(PWM_PIN, PWM_FREQ);
|
||||
@ -70,6 +68,7 @@ void setup() {
|
||||
}
|
||||
pinMode(ADC_IN, INPUT);
|
||||
|
||||
rotaryInit();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@ -82,13 +81,17 @@ void loop() {
|
||||
if (cycleCnt == 60) {
|
||||
maxCycleDelay = 0;
|
||||
}
|
||||
Serial.println("Tick");
|
||||
|
||||
|
||||
|
||||
int rotaryCount = getAndResetRotaryCount();
|
||||
int rotaryCount = getAndResetRotaryCount();
|
||||
Serial.println(rotaryCount);
|
||||
|
||||
noInterrupts();
|
||||
u_des += rotaryCount;
|
||||
u_des += rotaryCount;
|
||||
if (u_des < 0) {
|
||||
u_des = 0;
|
||||
}
|
||||
float my_u_curr = u_curr;
|
||||
uint16_t my_newPwm = newPwm;
|
||||
uint32_t my_cycleDelay = cycleDelay;
|
||||
|
@ -35,9 +35,9 @@ const uint8_t LCD_D7 = 7;
|
||||
const uint8_t LCD_ROWS = 2;
|
||||
const uint8_t LCD_COLS = 16;
|
||||
|
||||
const uint8_t ROTARY_A = ;
|
||||
const uint8_t ROTARY_B = ;
|
||||
const uint8_t SWITCH = ;
|
||||
const uint8_t ROTARY_A = 19;
|
||||
const uint8_t ROTARY_B = 18;
|
||||
const uint8_t SWITCH = 20;
|
||||
|
||||
|
||||
|
||||
|
28
rotary.cpp
28
rotary.cpp
@ -1,3 +1,4 @@
|
||||
#include <Arduino.h>
|
||||
#include <stdint.h>
|
||||
#include "hardware.h"
|
||||
#include "rotary.h"
|
||||
@ -9,14 +10,33 @@ volatile bool switchState = false;
|
||||
volatile unsigned long lastEvent = 0;
|
||||
|
||||
|
||||
int myDigitalRead(int a) {
|
||||
int r = 0;
|
||||
for (uint32_t i = 0; i < DEBOUNCING_REPEAT; i++) {
|
||||
if (digitalRead(a) == HIGH) {
|
||||
r++;
|
||||
} else {
|
||||
r--;
|
||||
}
|
||||
}
|
||||
int res = -1;
|
||||
if (r >= (DEBOUNCING_REPEAT / 2)) {
|
||||
res = 1;
|
||||
} else if (r <= -1 * (DEBOUNCING_REPEAT / 2)) {
|
||||
res = 0;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
void rotary_a_interrupt() {
|
||||
uint32_t currentEvent = millis();
|
||||
|
||||
if ((lastEvent == 0) || (lastEvent + DEBOUNCING_DEAD_TIME < currentEvent)) {
|
||||
lastEvent = currentEvent;
|
||||
|
||||
int a = digitalRead(ROTARY_A);
|
||||
int b = digitalRead(ROTARY_B);
|
||||
int a = myDigitalRead(ROTARY_A);
|
||||
int b = myDigitalRead(ROTARY_B);
|
||||
|
||||
if (((a != -1) && (b != -1))) {
|
||||
if (a == b) {
|
||||
@ -34,8 +54,8 @@ void rotary_b_interrupt() {
|
||||
if ((lastEvent == 0) || (lastEvent + DEBOUNCING_DEAD_TIME < currentEvent)) {
|
||||
lastEvent = currentEvent;
|
||||
|
||||
int a = digitalRead(ROTARY_A);
|
||||
int b = digitalRead(ROTARY_B);
|
||||
int a = myDigitalRead(ROTARY_A);
|
||||
int b = myDigitalRead(ROTARY_B);
|
||||
|
||||
if (((a != -1) && (b != -1))) {
|
||||
if (a == b) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user