Hi!
I have trouble with my Audrino NANO which is set to send HIGH or LOW on two PINs D2/D3 to my Digispark Attiny85 PINs P2/P3.
The 2 bit signal to the Digisparkshould should start one of three LED sequences to play until the
bit is shifted to another sequence.
I have tried the sequence on the Digisparks alone which works fine, but when hooked up to the NANO the LEDs just gives constant on, which is not even one of my sequences.
Anyone care to check my code if I missed something?
#include "EEPROM.h"
// ---------------------------------- Pin definitions -----
#define com_pin1 2
#define com_pin2 3
// --------------------------------------------------------------------------------------------------------------------
void setup() {
pinMode(com_pin1, OUTPUT); // Bit1 I/O outout to Sparky Pin2
pinMode(com_pin2, OUTPUT); // Bit2 I/O outout to Sparky Pin4
}
// --------------------------------------------------------------------------------------------------------------------
void loop(){
// send bits to Digispark Attiny, tre LED sequences
// 00 FIRE
digitalWrite(com_pin2, LOW);
digitalWrite(com_pin1, LOW);
delay(2000);
// 01 IDLE
digitalWrite(com_pin2, LOW);
digitalWrite(com_pin1, HIGH);
delay(2000);
// 11 SELECT
digitalWrite(com_pin2, HIGH);
digitalWrite(com_pin1, HIGH);
delay(2000);
}
// ---------------------------------- Pin definitions -----
#define led_low 0 // the PWM pin the leds is attached to
#define led_middle 1 // the PWM pin the leds is attached to
#define led_up 4 // the PWM pin the leds is attached to
#define com_pin1 2
#define com_pin2 3
// the setup routine runs once when you press reset:
void setup() {
// declare pins to be an output:
pinMode(led_low, OUTPUT); // Ledgroups LOW/MIDDLE/HIGH
pinMode(led_middle, OUTPUT);
pinMode(led_up, OUTPUT);
pinMode(com_pin1, INPUT_PULLUP); // Bit1 I/O inout from Nano Pin1
pinMode(com_pin2, INPUT_PULLUP); // Bit2 I/O inout from Nano Pin2
}
// ------------------------------------------------------------------------------------------------
// the loop routine runs over and over again forever:
void loop() {
if (digitalRead(com_pin2) == LOW){
if (digitalRead(com_pin1) == LOW){ // mode 1 = (00) fire
led_fire (0, 0, 255, 55, 10); // ledbrigthness (0-255), min, max, minwait, maxwait
}
}
if (digitalRead(com_pin1) == HIGH){ // mode 2 = (01) idle
led_idle (0, 2, 0, 255, 0, 300); // ledbrigthness (0-255), fadestep, min, max, minwait, maxwait
}
if (digitalRead(com_pin2) == HIGH){ // mode 3 = (11) select
led_select (0, 3, 0, 255, 1000, 130); // ledbrigthness (0-255), fadestep, min, max, minwait, maxwait
}
}
// --------------------------------------------------------------------------------------------
void led_fire (int ledbrightness, int min,int max, int minwait, int maxwait) {
int blink = max;
//while (digitalRead(com_pin2) == LOW){
// set the brightness of pins:
analogWrite(led_low, blink);
analogWrite(led_middle, blink);
analogWrite(led_up, blink);
blink = -blink; // leds alters max/min
// wait for x milliseconds upon min, max
if (ledbrightness <= min) {
delay(minwait);
}
if (ledbrightness >= max) {
delay(maxwait);
}
//}
}
// --------------------------------------------------------------------------------------------
void led_idle (int ledbrightness,int fadestep, int min,int max, int minwait, int maxwait) {
//while (digitalRead(com_pin1) == HIGH){
//set the brightness of pins:
analogWrite(led_low, ledbrightness);
analogWrite(led_middle, ledbrightness);
analogWrite(led_up, ledbrightness);
// change the brightness for next time through the loop:
ledbrightness = ledbrightness + fadestep;
// wait for x milliseconds upon min, max
if (ledbrightness <= min) {
delay(minwait);
}
if (ledbrightness >= max) {
delay(maxwait);
}
// reverse the direction of the fading at the ends of the fade:
if (ledbrightness <= min || ledbrightness >= max) {
fadestep = -fadestep;
}
// wait for x milliseconds to see the dimming effect
delay(8);
//}
}
// --------------------------------------------------------------------------------------------
void led_select (int ledbrightness,int fadestep, int min,int max, int minwait, int maxwait) {
int blink = max;
//while (digitalRead(com_pin2) == HIGH){
// set the brightness of pins:
analogWrite(led_low, ledbrightness);
analogWrite(led_middle, ledbrightness);
analogWrite(led_up, ledbrightness);
// change the brightness for next time through the loop:
ledbrightness = ledbrightness + fadestep;
// wait for x milliseconds upon min, max
if (ledbrightness <= min) {
delay(minwait);
}
if (ledbrightness >= max) {
for (int count = 1; count <= 16; count++) {
analogWrite(led_low, blink);
analogWrite(led_middle, blink);
analogWrite(led_up, blink);
blink = -blink; // leds alters max/min
delay(maxwait);
}
int blink = max; // Resets blink
}
// reverse the direction of the fading at the ends of the fade:
if (ledbrightness <= min || ledbrightness >= max) {
fadestep = -fadestep;
}
// wait for x milliseconds to see the dimming effect
delay(8);
//}
}