Close

Firmware v1.0

A project log for LED Lab Lamp Mod

Modification of the lamp with a magnifying glass to illuminate the workspace. The device emits warm and cold light.

grzegorzGrzegorz 08/25/2023 at 09:510 Comments

First version of the firmware is ready and deployment on ATtiny25. After upload firmware to MCU everything looks good. Now I will assembly everything together and testing.

Below I publish first version of the firmware.

/*
 * File:   main.c
 * Author: Grzegorz Wozny
 *
 * Created on 25 July 2023, 11:51
 */

#include <avr/io.h> 
#include <avr/interrupt.h>
#include <util/delay.h>

#define F_CPU 8000000UL
#define DIM_CH1 DDB0
#define DIM_CH2 DDB1
#define IC_CH1 DDB4 // Warm
#define IC_CH2 DDB2 // Cold
#define BUTTON DDB3

int cnt = 0;

int main(void) {
    // Fast mode PWM
    TCCR0A |= (1<<WGM01)|(1<<WGM00)|(1<<COM0A1)|(1<<COM0B1);
    TCCR0B |= (1<<CS00);
    
    // Enable LED5000 IC's
    DDRB |= (1<<IC_CH1);
    DDRB |= (1<<IC_CH2);
    PORTB |= (1<<IC_CH1); // Disable Channel 1
    PORTB |= (1<<IC_CH2); // Disable Channel 2
    
    // Make PWM pins outputs
    DDRB |= (1<<DIM_CH1);
    DDRB |= (1<<DIM_CH2);
    
    OCR0A = 0; // CH1
    OCR0B = 0; // CH2
    
    for(;;)
    {
        if ( !(PINB & (1 << BUTTON)) )
        {
            _delay_ms(20);
            if ( !(PINB & (1 << BUTTON)) )
            {
                cnt++;
                _delay_ms(20);
            }
        }
        
        switch (cnt)
        {
            case 1: // 100% Brightness for Warm and Cold Channel
                PORTB &= ~(1<<IC_CH1); // Enable Channel 1
                PORTB &= ~(1<<IC_CH2); // Enable Channel 2
                OCR0A = 255;
                OCR0B = 255;
                break;
            case 2: // 65% Brightness for Warm and Cold Channel
                PORTB &= ~(1<<IC_CH1); // Enable Channel 1
                PORTB &= ~(1<<IC_CH2); // Enable Channel 2
                OCR0A = 145;
                OCR0B = 145;
                break;                
            case 3: // 25% Brightness for Warm and Cold Channel
                PORTB &= ~(1<<IC_CH1); // Enable Channel 1
                PORTB &= ~(1<<IC_CH2); // Enable Channel 2
                OCR0A = 50;
                OCR0B = 50;
                break;  
            case 4: // 100% Brightness for Warm Channel
                PORTB &= ~(1<<IC_CH1); // Enable Channel 1
                PORTB |= (1<<IC_CH2); // Disable Channel 2
                OCR0A = 255;
                OCR0B = 0;
                break;                 
            case 5: // 65% Brightness for Warm Channel
                PORTB &= ~(1<<IC_CH1); // Enable Channel 1
                PORTB |= (1<<IC_CH2); // Disable Channel 2
                OCR0A = 145;
                OCR0B = 0;
                break;
            case 6: // 25% Brightness for Warm Channel
                PORTB &= ~(1<<IC_CH1); // Enable Channel 1
                PORTB |= (1<<IC_CH2); // Disable Channel 2
                OCR0A = 50;
                OCR0B = 0;
                break; 
            case 7: // 100% Brightness for Cold Channel
                PORTB |= (1<<IC_CH1); // Disable Channel 1
                PORTB &= ~(1<<IC_CH2); // Enable Channel 2
                OCR0A = 0;
                OCR0B = 255;
                break;
            case 8: // 65% Brightness for Cold Channel
                PORTB |= (1<<IC_CH1); // Disable Channel 1
                PORTB &= ~(1<<IC_CH2); // Enable Channel 2
                OCR0A = 0;
                OCR0B = 145;
                break;                
            case 9: // 25% Brightness for Cold Channel
                PORTB |= (1<<IC_CH1); // Disable Channel 1
                PORTB &= ~(1<<IC_CH2); // Enable Channel 2
                OCR0A = 0;
                OCR0B = 50;
                break;                  
            case 10: // 0% Brightness for Both Channel. Disable ICs.
                cnt = 0;
                PORTB |= (1<<IC_CH1); // Disable Channel 1
                PORTB |= (1<<IC_CH2); // Disable Channel 2
                OCR0A = 0;
                OCR0B = 0;
        }
    }    
}

Discussions