Initial import of support files for all Digistump boards - Digispark, Pro, DigiX - including libraries, examples, tools, and other support files for the Arduino IDE

This commit is contained in:
Erik Tylek Kettenburg
2014-12-19 08:45:50 -08:00
parent 97abdbf157
commit 7e7473a2d6
3567 changed files with 722870 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include "DigisparkRGB.h"
#include "Arduino.h"
#define set(x) |= (1<<x)
#define clr(x) &=~(1<<x)
#define inv(x) ^=(1<<x)
#define BLUE_CLEAR (pinlevelB &= ~(1 << BLUE)) // map BLUE to PB2
#define GREEN_CLEAR (pinlevelB &= ~(1 << GREEN)) // map BLUE to PB2
#define RED_CLEAR (pinlevelB &= ~(1 << RED)) // map BLUE to PB2
#define PORTB_MASK (1 << PB0) | (1 << PB1) | (1 << PB2)
#define BLUE PB2
#define GREEN PB1
#define RED PB0
unsigned char DigisparkPWMcompare[3];
volatile unsigned char DigisparkPWMcompbuff[3];
void DigisparkRGBBegin() {
pinMode(2, OUTPUT);
pinMode(1, OUTPUT);
pinMode(0, OUTPUT);
//CLKPR = (1 << CLKPCE); // enable clock prescaler update
//CLKPR = 0; // set clock to maximum (= crystal)
DigisparkPWMcompare[0] = 0x00;// set default PWM values
DigisparkPWMcompare[1] = 0x00;// set default PWM values
DigisparkPWMcompare[2] = 0x00;// set default PWM values
DigisparkPWMcompbuff[0] = 0x00;// set default PWM values
DigisparkPWMcompbuff[1] = 0x00;// set default PWM values
DigisparkPWMcompbuff[2] = 0x00;// set default PWM values
TIFR = (1 << TOV0); // clear interrupt flag
TIMSK = (1 << TOIE0); // enable overflow interrupt
TCCR0B = (1 << CS00); // start timer, no prescale
sei();
}
void DigisparkRGB(int pin,int value){
DigisparkPWMcompbuff[pin] = value;
}
void DigisparkRGBDelay(int ms) {
while (ms) {
_delay_ms(1);
ms--;
}
}
ISR (TIM0_OVF_vect) {
static unsigned char pinlevelB=PORTB_MASK;
static unsigned char softcount=0xFF;
PORTB = pinlevelB; // update outputs
if(++softcount == 0){ // increment modulo 256 counter and update
// the compare values only when counter = 0.
DigisparkPWMcompare[0] = DigisparkPWMcompbuff[0]; // verbose code for speed
DigisparkPWMcompare[1] = DigisparkPWMcompbuff[1]; // verbose code for speed
DigisparkPWMcompare[2] = DigisparkPWMcompbuff[2]; // verbose code for speed
pinlevelB = PORTB_MASK; // set all port pins high
}
// clear port pin on compare match (executed on next interrupt)
if(DigisparkPWMcompare[0] == softcount) RED_CLEAR;
if(DigisparkPWMcompare[1] == softcount) GREEN_CLEAR;
if(DigisparkPWMcompare[2] == softcount) BLUE_CLEAR;
}

View File

@@ -0,0 +1,14 @@
/*
DigisparkPWM.h - Library for pwm on PB2 on ATTINY85.
Created by Digistump
Released into the public domain.
*/
#ifndef DigisparkRGB_h
#define DigisparkRGB_h
void DigisparkRGBBegin();
void DigisparkRGBDelay(int ms);
void DigisparkRGB(int pin,int value);
#endif

View File

@@ -0,0 +1,58 @@
#include <DigisparkRGB.h>
/*
Digispark RGB
This example shows how to use soft PWM to fade 3 colors.
Note: This is only necessary for PB2 (pin 2) - Blue, as Red (pin 0) and Green (pin 1) as well as pin 4 support the standard Arduino analogWrite() function.
This example code is in the public domain.
*/
byte RED = 0;
byte BLUE = 2;
byte GREEN = 1;
byte COLORS[] = {RED, BLUE, GREEN};
// the setup routine runs once when you press reset:
void setup() {
DigisparkRGBBegin();
}
void loop ()
{
//direction: up = true, down = false
boolean dir = true;
int i = 0;
while(1)
{
fade(COLORS[i%3], dir);
i++;
dir = !dir;
}
}
void fade(byte Led, boolean dir)
{
int i;
//if fading up
if (dir)
{
for (i = 0; i < 256; i++)
{
DigisparkRGB(Led, i);
DigisparkRGBDelay(25);//1);
}
}
else
{
for (i = 255; i >= 0; i--)
{
DigisparkRGB(Led, i);
DigisparkRGBDelay(25);//1);
}
}
}

View File

@@ -0,0 +1,3 @@
DigisparkRGBBegin KEYWORD2
DigisparkRGB KEYWORD2
DigisparkRGBDelay KEYWORD2