Skip to content

Commit

Permalink
dim controller leds correctly (blue channel wasn't working)
Browse files Browse the repository at this point in the history
  • Loading branch information
Draradech committed Sep 18, 2022
1 parent b1955f0 commit 6080202
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 29 deletions.
2 changes: 1 addition & 1 deletion build-raspi.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
gcc -O3 -Wall -o nw -DTARGET_RASPI color.c config.c display.c main.c network.c simulation.c vector.c -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads/ -I/opt/vc/include/interface/vmcs_host/linux -L/opt/vc/lib -lm -lbrcmEGL -lbrcmGLESv2 -lbcm_host -lvchiq_arm
gcc -O3 -Wall -Wextra -Wno-unused-parameter -std=gnu11 -o nw -DTARGET_RASPI color.c config.c display.c main.c network.c simulation.c vector.c -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads/ -I/opt/vc/include/interface/vmcs_host/linux -L/opt/vc/lib -lm -lbrcmEGL -lbrcmGLESv2 -lbcm_host -lvchiq_arm
33 changes: 11 additions & 22 deletions controller/Clock4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,25 @@ void Clock4::attachInterrupt(void (*_callback)(void))

void Clock4::init(uint32_t cycles)
{
uint8_t psk = 1;

while(cycles > 255)
{
cycles /= 2;
psk += 1;
}

if (psk > 15)
if(cycles > 65535)
{
psk = 15;
cycles = 255;
cycles = 65535;
}

m_base = cycles;

TCCR4A = 0;
TCCR4B = (1 << PSR4) | psk;
TCCR4C = 0;
TCCR4D = 0;
TCCR4E = 0;
OCR4C = m_base - 1;
TCNT4 = 0;
TIFR4 = (1 << TOV4);
TIMSK4 = (1 << TOIE4);
TCCR1A = (1 << WGM10);
TCCR1B = (1 << WGM13) | (1 << CS10);
TCCR1C = 0;
OCR1A = m_base;
TCNT1 = 0;
TIFR1 = (1 << TOV1);
TIMSK1 = (1 << TOIE1);
}

uint8_t Clock4::value()
{
return TCNT4;
return TCNT3;
}

uint8_t Clock4::base()
Expand All @@ -71,7 +60,7 @@ boolean Clock4::expired()
return ret;
}

ISR(TIMER4_OVF_vect)
ISR(TIMER1_OVF_vect)
{
clock4_trigger = 1;
if(callback) callback();
Expand Down
4 changes: 1 addition & 3 deletions controller/Clock4.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class Clock4
void attachInterrupt(void (*_callback)(void));

private:
uint8_t m_base;
uint16_t m_base;
void init(uint32_t cycles);
};


6 changes: 3 additions & 3 deletions controller/controller.ino
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ void loop()
{
if(energy > speed)
{
analogWrite(LED_R, 255 - red / 4);
analogWrite(LED_G, 255 - grn / 5);
analogWrite(LED_B, 255 - blu / 129);
analogWrite(LED_R, 255 - red / 63);
analogWrite(LED_G, 255 - grn / 63);
analogWrite(LED_B, 255 - blu / 63);
}
else
{
Expand Down

0 comments on commit 6080202

Please sign in to comment.