Hi @all
Another Friday passed (i usually work on friday on my project) and after the problems with the IDE are solved i wanted to test some code.
Actually quite easy code read the button state on a pin and if the button is pressed it should trigger a relais to turn of or on depending on the previous state.
So wired up everything and instantly the relays went amok(turning of and on 3-6 times a second). So my first guess was that i receive all the time button state 1 so it tries to turn of and on every loop.
so i wired a little lamp into the circuit so see what happens. And the behaviour this lamp showed i made a video of it because i couldn't explain what happens.
https://goo.gl/photos/rtbu3QevH6r5LkUT6
(so no teensy included in this circuit) As you can see after the first 3 times it starts to delay or something, sometimes the lamp even stopped going on for several pushes. Anyone a idea whats going on here?
So i had the thing already once tested on a breadboard. (because i'm a completely beginner)
https://goo.gl/photos/RYwmQoQbiYfYpNnh8
there everything worked as expected... but i actually lost my code from past there...
So the funny thing was yesterday that if i wired the button to the pin 19 i always received state 1 on the serial monitor. if i wired it to the 23 i firstly didn't get any output so i would expect 0 until the first time i pressed the button from then on it kept it state to 1 independent of time and other button pushes. Did use the wrong method to read the pin?
and by the way whats the difference between digitalRead and digitalReadFast?
regards sev
Another Friday passed (i usually work on friday on my project) and after the problems with the IDE are solved i wanted to test some code.
Actually quite easy code read the button state on a pin and if the button is pressed it should trigger a relais to turn of or on depending on the previous state.
So wired up everything and instantly the relays went amok(turning of and on 3-6 times a second). So my first guess was that i receive all the time button state 1 so it tries to turn of and on every loop.
so i wired a little lamp into the circuit so see what happens. And the behaviour this lamp showed i made a video of it because i couldn't explain what happens.
https://goo.gl/photos/rtbu3QevH6r5LkUT6
(so no teensy included in this circuit) As you can see after the first 3 times it starts to delay or something, sometimes the lamp even stopped going on for several pushes. Anyone a idea whats going on here?
So i had the thing already once tested on a breadboard. (because i'm a completely beginner)
https://goo.gl/photos/RYwmQoQbiYfYpNnh8
there everything worked as expected... but i actually lost my code from past there...
So the funny thing was yesterday that if i wired the button to the pin 19 i always received state 1 on the serial monitor. if i wired it to the 23 i firstly didn't get any output so i would expect 0 until the first time i pressed the button from then on it kept it state to 1 independent of time and other button pushes. Did use the wrong method to read the pin?
Code:
#define USE_OCTOWS2811
#include "Table.h"
#include<OctoWS2811.h>
#include<FastLED.h>
#define NUM_LEDS_PER_STRIP 164
#define NUM_STRIPS 8
int numOfTopLeds= 168;
int numOfFrontLeds= 0;
int numOfLeftLeds= 0;
int numOfRightLeds= 0;
int numOfBackLeds= 0;
int numOfFeetLeds= 7;
const int maxBrightness=150;
int currentBrigthness =130;
Table table = Table();
//TODO need to check the pins in reality. these are just some random numbers.
//pin 18 is the airpump
int buttonMutePumpPin = 23;
int buttonBrightnessPin = 19;
int buttonNextAnimationPin =20;
int buttonUnknownsPin=21;
bool isButtonTogglePumpPressed =false;
bool isButtonBrightnessPressed=false;
bool isButtonNextAnimationPressed=false;
bool isButtonUnknownPressed=false;
CRGB leds[NUM_STRIPS * NUM_LEDS_PER_STRIP];
Table::Table() {
// TODO Auto-generated constructor stub
}
Table::~Table() {
// TODO Auto-generated destructor stub
}
void setup() {
LEDS.addLeds<OCTOWS2811>(leds, NUM_LEDS_PER_STRIP);
//LEDS.addLeds(leds, 164);
LEDS.setBrightness(currentBrigthness);
FastLED.setBrightness(currentBrigthness);
pinMode(buttonMutePumpPin, INPUT);
pinMode(buttonBrightnessPin, INPUT);
pinMode(buttonNextAnimationPin, INPUT);
pinMode(buttonUnknownsPin, INPUT);
}
void Table::updateButtonStates(){
isButtonTogglePumpPressed=0;
bool isButtonTogglePumpPressed =digitalRead(buttonMutePumpPin);
bool isButtonBrightnessPressed=digitalRead(buttonBrightnessPin);
isButtonNextAnimationPressed=digitalRead(buttonNextAnimationPin);
isButtonUnknownPressed=digitalRead(buttonUnknownsPin);
if(isButtonTogglePumpPressed){
//table.airpump.toogleAirpumpState();
Serial.println(isButtonTogglePumpPressed);
}
if(isButtonBrightnessPressed){
currentBrigthness = currentBrigthness + 15;
if(currentBrigthness > maxBrightness){
currentBrigthness =10;
}
LEDS.setBrightness(currentBrigthness);
FastLED.setBrightness(currentBrigthness);
}
}
void someAnymation() {
static uint8_t hue = 0;
for (int i = 0; i < NUM_STRIPS; i++) {
for (int j = 0; j < NUM_LEDS_PER_STRIP; j++) {
leds[(i * NUM_LEDS_PER_STRIP) + j] = CHSV((32 * i) + hue + j, 192,
255);
}
}
// Set the first n leds on each strip to show which strip it is
for (int i = 0; i < NUM_STRIPS; i++) {
for (int j = 0; j <= i; j++) {
leds[(i * NUM_LEDS_PER_STRIP) + j] = CRGB::Red;
}
}
hue++;
}
void loop() {
someAnymation();
//Fire2012();
LEDS.show();
LEDS.delay(10);
table.updateButtonStates();
}
and by the way whats the difference between digitalRead and digitalReadFast?
regards sev
Last edited: