ATtiny402 2023 Christmas gift for all
I've made 2018, 2019, 2020, and now 2023 Christmas gift for all.. I made the 3d print so you can do what electronic design you want. But the one I chose was the ATtiny402, Because I bought a bunch for 48 cents a piece. They are easy to program. But if you want I've included the schematics and code for what I did.
The 3dprint can be downloaded from https://cults3d.com/en/3d-model/art/2023-christmas-gift-to-all
/* * ATtiny402-2023-Christmas-Gift-for-free.c * * Created: 10/27/2023 09:07:06 * Author : Sherman Stebbins * Programmed with Microchip studio 7.0 */
#define F_CPU 10000000UL#include <avr/io.h>#include <util/delay.h>#include <avr/interrupt.h>#include <stdlib.h> //for rand()#define ModeMax 5
volatile uint8_t mode = 0;volatile uint8_t randLoops = 0;volatile uint8_t sleepstate = 0;
void gotosleep(void);
int main(void){ CCP = 0xD8; CLKCTRL_MCLKCTRLB = 0b00000001; //pull up pin 2 and set it to trigger int on falling edge: PORTA.PIN2CTRL = PORT_ISC_RISING_gc; //this was my fix for changing current draw sei(); //Set enable interrupt //set sleep to power down //SLPCTRL.CTRLA = 0b00000101; //sherms way SLPCTRL.CTRLA = SLPCTRL_SMODE_PDOWN_gc | SLPCTRL_SEN_bm; //Microchip studio showed this gotosleep(); //sleep while (1){ //randLoops = (rand() % 100)+20;//3; //random 3-12 loops for display // mode=3;
switch(mode){ case 0: PORTA_OUT = PIN3_bm|PIN7_bm|PIN6_bm|PIN1_bm; _delay_ms(10000); PORTA_OUTCLR = PIN3_bm|PIN7_bm|PIN6_bm|PIN1_bm; break; case 1: PORTA_OUT = PIN3_bm|PIN7_bm|PIN6_bm|PIN1_bm; _delay_ms(12000); PORTA_OUTCLR = PIN3_bm|PIN7_bm|PIN6_bm|PIN1_bm; break; case 2: PORTA_OUT = PIN3_bm|PIN7_bm|PIN6_bm|PIN1_bm; _delay_ms(15000); PORTA_OUTCLR = PIN3_bm|PIN7_bm|PIN6_bm|PIN1_bm; break; case 3: PORTA_OUT = PIN3_bm|PIN7_bm|PIN6_bm|PIN1_bm; _delay_ms(20000); PORTA_OUTCLR = PIN3_bm|PIN7_bm|PIN6_bm|PIN1_bm; break; case 4: PORTA_OUT = PIN3_bm|PIN7_bm|PIN6_bm|PIN1_bm; _delay_ms(25000); PORTA_OUTCLR = PIN3_bm|PIN7_bm|PIN6_bm|PIN1_bm; break; case 5: PORTA_OUT = PIN3_bm|PIN7_bm|PIN6_bm|PIN1_bm; _delay_ms(30000); PORTA_OUTCLR = PIN3_bm|PIN7_bm|PIN6_bm|PIN1_bm; break;
default: break; } // mode=3; mode= (rand() % ModeMax); //Randomly select next mode/* if(mode++ > ModeMax-1){ mode=0; }*/ gotosleep(); }}
void gotosleep(void){ PORTA.DIRSET = 0b00000000;
sei(); SLPCTRL.CTRLA = 0b00000101; //set power down and sleep enable asm("sleep"); //sleep PORTA_DIRSET = PIN1_bm | PIN3_bm | PIN6_bm | PIN7_bm;
}
ISR(PORTA_PORT_vect){ if(sleepstate){ sleepstate=0; } //PORTA.INTFLAGS = 0x04; //clear int flag, from Ben Heck.. PORTA.INTFLAGS = PORT_INT2_bm; //not tested, got from iotn402.h}
#define F_CPU 10000000UL#include <avr/io.h>#include <util/delay.h>#include <avr/interrupt.h>#include <stdlib.h> //for rand()#define ModeMax 5
volatile uint8_t mode = 0;volatile uint8_t randLoops = 0;volatile uint8_t sleepstate = 0;
void gotosleep(void);
int main(void){ CCP = 0xD8; CLKCTRL_MCLKCTRLB = 0b00000001; //pull up pin 2 and set it to trigger int on falling edge: PORTA.PIN2CTRL = PORT_ISC_RISING_gc; //this was my fix for changing current draw sei(); //Set enable interrupt //set sleep to power down //SLPCTRL.CTRLA = 0b00000101; //sherms way SLPCTRL.CTRLA = SLPCTRL_SMODE_PDOWN_gc | SLPCTRL_SEN_bm; //Microchip studio showed this gotosleep(); //sleep while (1){ //randLoops = (rand() % 100)+20;//3; //random 3-12 loops for display // mode=3;
switch(mode){ case 0: PORTA_OUT = PIN3_bm|PIN7_bm|PIN6_bm|PIN1_bm; _delay_ms(10000); PORTA_OUTCLR = PIN3_bm|PIN7_bm|PIN6_bm|PIN1_bm; break; case 1: PORTA_OUT = PIN3_bm|PIN7_bm|PIN6_bm|PIN1_bm; _delay_ms(12000); PORTA_OUTCLR = PIN3_bm|PIN7_bm|PIN6_bm|PIN1_bm; break; case 2: PORTA_OUT = PIN3_bm|PIN7_bm|PIN6_bm|PIN1_bm; _delay_ms(15000); PORTA_OUTCLR = PIN3_bm|PIN7_bm|PIN6_bm|PIN1_bm; break; case 3: PORTA_OUT = PIN3_bm|PIN7_bm|PIN6_bm|PIN1_bm; _delay_ms(20000); PORTA_OUTCLR = PIN3_bm|PIN7_bm|PIN6_bm|PIN1_bm; break; case 4: PORTA_OUT = PIN3_bm|PIN7_bm|PIN6_bm|PIN1_bm; _delay_ms(25000); PORTA_OUTCLR = PIN3_bm|PIN7_bm|PIN6_bm|PIN1_bm; break; case 5: PORTA_OUT = PIN3_bm|PIN7_bm|PIN6_bm|PIN1_bm; _delay_ms(30000); PORTA_OUTCLR = PIN3_bm|PIN7_bm|PIN6_bm|PIN1_bm; break;
default: break; } // mode=3; mode= (rand() % ModeMax); //Randomly select next mode/* if(mode++ > ModeMax-1){ mode=0; }*/ gotosleep(); }}
void gotosleep(void){ PORTA.DIRSET = 0b00000000;
sei(); SLPCTRL.CTRLA = 0b00000101; //set power down and sleep enable asm("sleep"); //sleep PORTA_DIRSET = PIN1_bm | PIN3_bm | PIN6_bm | PIN7_bm;
}
ISR(PORTA_PORT_vect){ if(sleepstate){ sleepstate=0; } //PORTA.INTFLAGS = 0x04; //clear int flag, from Ben Heck.. PORTA.INTFLAGS = PORT_INT2_bm; //not tested, got from iotn402.h}