Hi All,
I am new to the Teensy boards, but coming from Arduino, I am loving it so far.
This is my first official build with a Teensy board and I have been testing along the way. I tested my keys, then the rotary encoders and finally the RGB LEDs.
I fear that I may have killed my board though.
I had just finished my wiring and was completing testing of my LEDs.
I pushed my code to the Teensy and it stopped responding. I am not sure at what point it stopped.
The way I had my board mounted, I had to pry it up to get access to the reset button, but I tried pressing it and the red light near the usb port did not appear. I also read some suggestions and tried holding the button for 15 and 20 seconds respectively and also plugging it in with the button pressed. It is lifeless.
My biggest confusion is that I did not make any wiring changes or even move it between when it was working and when it became non-responseive, So it is hard to tell if something shorted out.
Please let me know if there is anything else I can do to try to revive it.
My code is below and also some pictures in my WIP project (it is a macro/utility keyboad).
Any help will be much appreciated.
Images:
https://imgur.com/a/v28O6jF
Code:
I am new to the Teensy boards, but coming from Arduino, I am loving it so far.
This is my first official build with a Teensy board and I have been testing along the way. I tested my keys, then the rotary encoders and finally the RGB LEDs.
I fear that I may have killed my board though.
I had just finished my wiring and was completing testing of my LEDs.
I pushed my code to the Teensy and it stopped responding. I am not sure at what point it stopped.
The way I had my board mounted, I had to pry it up to get access to the reset button, but I tried pressing it and the red light near the usb port did not appear. I also read some suggestions and tried holding the button for 15 and 20 seconds respectively and also plugging it in with the button pressed. It is lifeless.
My biggest confusion is that I did not make any wiring changes or even move it between when it was working and when it became non-responseive, So it is hard to tell if something shorted out.
Please let me know if there is anything else I can do to try to revive it.
My code is below and also some pictures in my WIP project (it is a macro/utility keyboad).
Any help will be much appreciated.
Images:
https://imgur.com/a/v28O6jF
Code:
Code:
#include <Keypad.h>
//Setup Knobs
// Top (A)
int knobA_CLK = 23;
int knobA_DT = 22;
int knobA_SW = 21;
int knobA_counter = 0;
int knobA_currentStateCLK;
int knobA_lastStateCLK;
String knobA_currentDir ="";
unsigned long knobA_lastButtonPress = 0;
// Middle (B)
int knobB_CLK = 18;
int knobB_DT = 19;
int knobB_SW = 20;
int knobB_counter = 0;
int knobB_currentStateCLK;
int knobB_lastStateCLK;
String knobB_currentDir ="";
unsigned long knobB_lastButtonPress = 0;
// Bottom (C)
int knobC_CLK = 14;
int knobC_DT = 15;
int knobC_SW = 16;
int knobC_counter = 0;
int knobC_currentStateCLK;
int knobC_lastStateCLK;
String knobC_currentDir ="";
unsigned long knobC_lastButtonPress = 0;
// Setup LEDs
// LED A
int ledA_R = 8;
int ledA_G = 9;
int ledA_B = 10;
// LED B
int ledB_R = 11;
int ledB_G = 12;
int ledB_B = 13;
// LED C
int ledC_R = 34;
int ledC_G = 28;
int ledC_B = 24;
// LED D
int ledD_R = 33;
int ledD_G = 29;
int ledD_B = 25;
// Setup Keys
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'A', 'E', 'I', 'M'},
{'B', 'F', 'J', 'N'},
{'C', 'G', 'K', 'O'},
{'D', 'H', 'L', 'P'}
};
byte rowPins[ROWS] = {4, 5, 6, 7};
byte colPins[COLS] = {0, 1, 2, 3};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup(){
// Setup Serial Monitor
Serial.begin(9600);
// Set encoder pins as inputs
pinMode(knobA_CLK,INPUT);
pinMode(knobA_DT,INPUT);
pinMode(knobA_SW, INPUT_PULLUP);
pinMode(knobB_CLK,INPUT);
pinMode(knobB_DT,INPUT);
pinMode(knobB_SW, INPUT_PULLUP);
pinMode(knobC_CLK,INPUT);
pinMode(knobC_DT,INPUT);
pinMode(knobC_SW, INPUT_PULLUP);
// Read the initial state
knobA_lastStateCLK = digitalRead(knobA_CLK);
knobB_lastStateCLK = digitalRead(knobB_CLK);
knobC_lastStateCLK = digitalRead(knobC_CLK);
//RGB Leds
pinMode(ledA_R, OUTPUT);
pinMode(ledA_G, OUTPUT);
pinMode(ledA_B, OUTPUT);
}
void loop(){
// Read the current state of CLK
knobA_currentStateCLK = digitalRead(knobA_CLK);
knobB_currentStateCLK = digitalRead(knobB_CLK);
knobC_currentStateCLK = digitalRead(knobC_CLK);
// Knob A
if (knobA_currentStateCLK != knobA_lastStateCLK && knobA_currentStateCLK == 1){
if (digitalRead(knobA_DT) != knobA_currentStateCLK) {
knobA_counter --;
knobA_currentDir ="CW";
} else {
knobA_counter ++;
knobA_currentDir ="CCW";
}
RGB_color(0, 255, 0); // Green
Serial.print("Direction: ");
Serial.print(knobA_currentDir);
Serial.print(" | Counter: ");
Serial.println(knobA_counter);
}
knobA_lastStateCLK = knobA_currentStateCLK;
int knobA_btnState = digitalRead(knobA_SW);
if (knobA_btnState == LOW) {
if (millis() - knobA_lastButtonPress > 50) {
Serial.println("Button pressed!");
}
knobA_lastButtonPress = millis();
RGB_color(255, 0, 0); // Red
}
// Knob B
if (knobB_currentStateCLK != knobB_lastStateCLK && knobB_currentStateCLK == 1){
if (digitalRead(knobB_DT) != knobB_currentStateCLK) {
knobB_counter --;
knobB_currentDir ="CW";
} else {
knobB_counter ++;
knobB_currentDir ="CCW";
}
RGB_color(0, 255, 0); // Green
Serial.print("Direction: ");
Serial.print(knobB_currentDir);
Serial.print(" | Counter: ");
Serial.println(knobB_counter);
}
knobB_lastStateCLK = knobB_currentStateCLK;
int knobB_btnState = digitalRead(knobB_SW);
if (knobB_btnState == LOW) {
if (millis() - knobB_lastButtonPress > 50) {
Serial.println("Button pressed!");
}
knobB_lastButtonPress = millis();
RGB_color(255, 0, 0); // Red
}
// Knob C
if (knobC_currentStateCLK != knobC_lastStateCLK && knobC_currentStateCLK == 1){
if (digitalRead(knobC_DT) != knobC_currentStateCLK) {
knobC_counter --;
knobC_currentDir ="CW";
} else {
knobC_counter ++;
knobC_currentDir ="CCW";
}
RGB_color(0, 255, 0); // Green
Serial.print("Direction: ");
Serial.print(knobC_currentDir);
Serial.print(" | Counter: ");
Serial.println(knobC_counter);
}
knobC_lastStateCLK = knobC_currentStateCLK;
int knobC_btnState = digitalRead(knobC_SW);
if (knobC_btnState == LOW) {
if (millis() - knobC_lastButtonPress > 50) {
Serial.println("Button pressed!");
}
knobC_lastButtonPress = millis();
RGB_color(255, 0, 0); // Red
}
delay(1);
// Keypress
char customKey = customKeypad.getKey();
if (customKey){
Serial.println(customKey);
Keyboard.press(customKey);
RGB_color(0, 0, 255); // Blue
delay(10);
Keyboard.releaseAll();
}
//BB
// RGB_color(0, 0, 255); // Blue
// delay(1000);
// RGB_color(0, 255, 0); // Green
// delay(1000);
// RGB_color(255, 0, 0); // Red
// delay(1000);
// RGB_color(255, 255, 125); // Raspberry
// delay(1000);
// RGB_color(0, 255, 255); // Cyan
// delay(1000);
// RGB_color(255, 0, 255); // Magenta
// delay(1000);
// RGB_color(255, 255, 0); // Yellow
// delay(1000);
// RGB_color(255, 255, 255); // White
// delay(1000);
RGB_color(0, 0, 0);
}
void RGB_color(int red_light_value, int green_light_value, int blue_light_value)
{
analogWrite(ledA_R, red_light_value);
analogWrite(ledA_G, green_light_value);
analogWrite(ledA_B, blue_light_value);
analogWrite(ledB_R, red_light_value);
analogWrite(ledB_G, green_light_value);
analogWrite(ledB_B, blue_light_value);
analogWrite(ledC_R, red_light_value);
analogWrite(ledC_G, green_light_value);
analogWrite(ledC_B, blue_light_value);
analogWrite(ledD_R, red_light_value);
analogWrite(ledD_G, green_light_value);
analogWrite(ledD_B, blue_light_value);
}