mirror of
https://github.com/digistump/DigistumpArduino.git
synced 2025-09-17 17:32:25 -07:00
switch to setup for Arduino Boards Manager
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
#define USB_CFG_DEVICE_NAME 'D','i','g','i','B','l','i','n','k'
|
||||
#define USB_CFG_DEVICE_NAME_LEN 9
|
||||
#include <DigiUSB.h>
|
||||
byte in = 0;
|
||||
int Blue = 0;
|
||||
int Red = 0;
|
||||
int Green = 0;
|
||||
|
||||
int next = 0;
|
||||
|
||||
void setup() {
|
||||
DigiUSB.begin();
|
||||
pinMode(0,OUTPUT);
|
||||
pinMode(1,OUTPUT);
|
||||
pinMode(2,OUTPUT);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
setBlue();
|
||||
DigiUSB.refresh();
|
||||
setBlue();
|
||||
if (DigiUSB.available() > 0) {
|
||||
in = 0;
|
||||
|
||||
in = DigiUSB.read();
|
||||
if (next == 0){
|
||||
if(in == 115){
|
||||
next = 1;
|
||||
DigiUSB.println("Start");
|
||||
}
|
||||
}
|
||||
else if (next == 1){
|
||||
Red = in;
|
||||
DigiUSB.print("Red ");
|
||||
DigiUSB.println(in,DEC);
|
||||
next = 2;
|
||||
}
|
||||
else if (next == 2){
|
||||
Green = in;
|
||||
DigiUSB.print("Green ");
|
||||
DigiUSB.println(in,DEC);
|
||||
next = 3;
|
||||
}
|
||||
else if (next == 3){
|
||||
Blue = in;
|
||||
DigiUSB.print("Blue ");
|
||||
DigiUSB.println(in,DEC);
|
||||
next = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
analogWrite(0,Red);
|
||||
analogWrite(1,Green);
|
||||
setBlue();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void setBlue(){
|
||||
if(Blue == 0){
|
||||
digitalWrite(2,LOW);
|
||||
return;
|
||||
}
|
||||
else if(Blue == 255){
|
||||
digitalWrite(2,HIGH);
|
||||
return;
|
||||
}
|
||||
// On period
|
||||
for (int x=0;x<Blue;x++){
|
||||
digitalWrite(2,HIGH);
|
||||
}
|
||||
|
||||
// Off period
|
||||
|
||||
for(int x=0;x<(255-Blue);x++){
|
||||
digitalWrite(2,LOW);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,42 @@
|
||||
#include <DigiUSB.h>
|
||||
|
||||
void setup() {
|
||||
DigiUSB.begin();
|
||||
}
|
||||
|
||||
void get_input() {
|
||||
// when there are no characters to read
|
||||
while (1==1) {
|
||||
if(DigiUSB.available()){
|
||||
//something to read
|
||||
DigiUSB.read();
|
||||
break;
|
||||
}
|
||||
// refresh the usb port
|
||||
DigiUSB.refresh();
|
||||
delay(10);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
DigiUSB.refresh();
|
||||
//print output
|
||||
float value = analogRead(1); //This is Pin3
|
||||
if(value>1020)
|
||||
value = 255;
|
||||
else if(value<2)
|
||||
value = 0;
|
||||
else
|
||||
value = value/4;
|
||||
//send value
|
||||
|
||||
value = round(byte(value));
|
||||
DigiUSB.write(value);
|
||||
|
||||
//wait for response
|
||||
get_input();
|
||||
|
||||
}
|
@@ -0,0 +1,81 @@
|
||||
/* USB LCD */
|
||||
|
||||
//#define DEBUG
|
||||
#include <TinyWireM.h> // I2C Master lib for ATTinys which use USI - comment this out to use with standard arduinos
|
||||
#include <LiquidCrystal_I2C.h> // for LCD w/ GPIO MODIFIED for the ATtiny85
|
||||
#include <DigiUSB.h>
|
||||
|
||||
#define GPIO_ADDR 0x27 // (PCA8574A A0-A2 @5V) typ. A0-A3 Gnd 0x20 / 0x38 for A - 0x27 is the address of the Digispark LCD modules.
|
||||
int currentLine = 0;
|
||||
boolean clearOnNext = 0;
|
||||
boolean backlight = 1;
|
||||
|
||||
LiquidCrystal_I2C lcd(GPIO_ADDR,16,2); // set address & 16 chars / 2 lines
|
||||
|
||||
|
||||
void setup(){
|
||||
DigiUSB.begin();
|
||||
TinyWireM.begin(); // initialize I2C lib - comment this out to use with standard arduinos
|
||||
lcd.init(); // initialize the lcd
|
||||
lcd.backlight(); // Print a message to the LCD.
|
||||
lcd.setCursor(0, currentLine);
|
||||
}
|
||||
|
||||
|
||||
void get_input() {
|
||||
|
||||
int lastRead;
|
||||
// when there are no characters to read, or the character isn't a newline
|
||||
while (1==1) {
|
||||
if(DigiUSB.available()){
|
||||
//something to read
|
||||
lastRead = DigiUSB.read();
|
||||
if(lastRead == '\n'){
|
||||
|
||||
|
||||
if(currentLine > 0)
|
||||
currentLine = 0;
|
||||
else
|
||||
currentLine = 1;
|
||||
|
||||
clearOnNext = 1;
|
||||
|
||||
lcd.setCursor(0, currentLine);
|
||||
|
||||
}
|
||||
else if(lastRead == 172){ //not sign "¬" send it with the send program to toggle the backlight
|
||||
if(backlight){
|
||||
lcd.noBacklight();
|
||||
backlight = 0;
|
||||
}
|
||||
else{
|
||||
lcd.backlight();
|
||||
backlight = 1;
|
||||
}
|
||||
DigiUSB.read(); //read to nothing to get rid of newline that should come after it
|
||||
|
||||
}
|
||||
else{
|
||||
if(clearOnNext){
|
||||
lcd.print(" "); //clear a single line
|
||||
lcd.setCursor(0, currentLine);
|
||||
clearOnNext=0;
|
||||
}
|
||||
lcd.print(char(lastRead));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
// refresh the usb port
|
||||
DigiUSB.refresh();
|
||||
delay(10);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void loop(){
|
||||
get_input();
|
||||
}
|
31
digistump-avr/libraries/DigisparkUSB/examples/Echo/Echo.ino
Normal file
31
digistump-avr/libraries/DigisparkUSB/examples/Echo/Echo.ino
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <DigiUSB.h>
|
||||
|
||||
void setup() {
|
||||
DigiUSB.begin();
|
||||
}
|
||||
|
||||
void get_input() {
|
||||
int lastRead;
|
||||
// when there are no characters to read, or the character isn't a newline
|
||||
while (true) { // loop forever
|
||||
if (DigiUSB.available()) {
|
||||
// something to read
|
||||
lastRead = DigiUSB.read();
|
||||
DigiUSB.write(lastRead);
|
||||
|
||||
if (lastRead == '\n') {
|
||||
break; // when we get a newline, break out of loop
|
||||
}
|
||||
}
|
||||
|
||||
// refresh the usb port for 10 milliseconds
|
||||
DigiUSB.delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// print output
|
||||
DigiUSB.println("Waiting for input...");
|
||||
// get input
|
||||
get_input();
|
||||
}
|
Reference in New Issue
Block a user