Sigurthr
0
- Joined
- Dec 11, 2011
- Messages
- 4,364
- Points
- 83
I looked into it and the 85 does have runtime addressable EEPROM. I'm learning the functions for it now. When I write up the program I'll test it out too. Should be easy enough to implement.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
I looked into it and the 85 does have runtime addressable EEPROM. I'm learning the functions for it now. When I write up the program I'll test it out too. Should be easy enough to implement.
Presumably we can guard by only putting a write event inside the button function, and then only putting a read at the very beginning of the startup, at the end of a button press. No?
When you say limited, are you talking hundreds, thousands, millions?
Btw, it comes to ~2.5kB so no way it will fit on the ATT13, gotta be a better uC (I recommend the 85).
Do you want me to post the program code here or upload it for private download or email it to you or...?
// RHD's TTL Color Selector
// Programming by Matt "Sigurthr" Giordano 08/13/2014
// www.SigurthrEnterprises.com
// Sigurthr@SigurthrEnterprises.com
// ATTiny85 Physical Pinout - innermost designation is code addressable
// _______
// Reset _| |_| |_ Vcc
// ADC3 Pin3 3 _| |_ 2 Pin2 ADC1
// ADC2 Pin4 A2 _| ATT85 |_ 1 Pin1 Digital-1
// Gnd _| |_ 0 Pin0 Digital-0
// |_______|
#include <EEPROM.h> // include the EEPROM Memory library
int PressDetects = 0;
int ButtonPin = 3; // see pinout
int ColorOnePin = 0; // see pinout
int ColorTwoPin = 1; // see pinout
int ColorThreePin = 2; // see pinout
int MemVar;
int ButtonPinState;
int ColorChoice;
int MemoryLocation = 1;
unsigned int TriggerCount = 10; // threshold for debounce
void setup (){ // this subroutine runs once upon startup
MemVar = EEPROM.read(MemoryLocation); // read EEPROM on power on
pinMode (0, OUTPUT); // set pin 0 to output
pinMode (1, OUTPUT); // set pin 1 to output
pinMode (2, OUTPUT); // set pin 2 to output
pinMode (3, INPUT); // set pin 3 to input
}
void loop(){ // this subroutine runs continuously after setup finishes
ButtonPinState = digitalRead(ButtonPin); // read ButtonPin to ButtonPinState
if (MemVar == 0 || 255){ // first time an EEPROM is read it reads as 255
MemVar = 1;
}
if (ButtonPinState == HIGH){ // when ButtonPinState is HIGH...
++ PressDetects; // increment detection variable
}
if (PressDetects >= TriggerCount) { // when threshold is exceeded...
++ MemVar; // increment memory variable
PressDetects = 0; // reset button detector
EEPROM.write(MemoryLocation, MemVar); // write color to memory
if (MemVar >= 9){ // on 9th button press...
MemVar = 1; // reset color
}
}
if (MemVar == 8){ // on 8th button press...
ColorChoice = random(1, 7); // choose random color
}
else { // if MemVar != 0,8,9,10, or larger...
ColorChoice = MemVar;
}
if (ColorChoice == 1){
digitalWrite(ColorOnePin, HIGH);
digitalWrite(ColorTwoPin, HIGH);
digitalWrite(ColorThreePin, HIGH);
}
if (ColorChoice == 2){
digitalWrite(ColorOnePin, HIGH);
digitalWrite(ColorTwoPin, LOW);
digitalWrite(ColorThreePin, LOW);
}
if (ColorChoice == 3){
digitalWrite(ColorOnePin, HIGH);
digitalWrite(ColorTwoPin, HIGH);
digitalWrite(ColorThreePin, LOW);
}
if (ColorChoice == 4){
digitalWrite(ColorOnePin, LOW);
digitalWrite(ColorTwoPin, HIGH);
digitalWrite(ColorThreePin, LOW);
}
if (ColorChoice == 5){
digitalWrite(ColorOnePin, LOW);
digitalWrite(ColorTwoPin, HIGH);
digitalWrite(ColorThreePin, HIGH);
}
if (ColorChoice == 6){
digitalWrite(ColorOnePin, LOW);
digitalWrite(ColorTwoPin, LOW);
digitalWrite(ColorThreePin, HIGH);
}
if (ColorChoice == 7){
digitalWrite(ColorOnePin, HIGH);
digitalWrite(ColorTwoPin, LOW);
digitalWrite(ColorThreePin, HIGH);
}
}
EEPROM.write(MemoryLocation, MemVar); // write color to memory
if (MemVar >= 9){ // on 9th button press...
MemVar = 1; // reset color
}
if (MemVar >= 9){ // on 9th button press...
MemVar = 1; // reset color
}
EEPROM.write(MemoryLocation, MemVar); // write color to memory
// RHD's TTL Color Selector
// Programming by Matt "Sigurthr" Giordano 08/13/2014
// www.SigurthrEnterprises.com
// Sigurthr@SigurthrEnterprises.com
// ATTiny85 Physical Pinout - innermost designation is code addressable
// _______
// Reset _| |_| |_ Vcc
// ADC3 Pin3 3 _| |_ 2 Pin2 ADC1
// ADC2 Pin4 A2 _| ATT85 |_ 1 Pin1 Digital-1
// Gnd _| |_ 0 Pin0 Digital-0
// |_______|
#include <EEPROM.h> // include the EEPROM Memory library
int PressDetects = 0;
int ButtonPin = 3; // see pinout
int ColorOnePin = 0; // see pinout
int ColorTwoPin = 1; // see pinout
int ColorThreePin = 2; // see pinout
int MemVar;
int ButtonPinState;
int ColorChoice;
int RandomChoiceA;
int RandomChoiceB;
int RandomChoiceC;
int MemoryLocation = 1;
unsigned int TriggerCount = 10; // threshold for debounce
void setup (){ // this subroutine runs once upon startup
MemVar = EEPROM.read(MemoryLocation); // read EEPROM on power on
pinMode (0, OUTPUT); // set pin 0 to output
pinMode (1, OUTPUT); // set pin 1 to output
pinMode (2, OUTPUT); // set pin 2 to output
pinMode (3, INPUT); // set pin 3 to input
if (MemVar == 8){ // if we're set on the random mode...
RandomChoiceA = random(1, 2); // choose HIGH/LOW randomly
RandomChoiceB = random(1, 2); // choose HIGH/LOW randomly
RandomChoiceC = random(1, 2); // choose HIGH/LOW randomly
}
}
void loop(){ // this subroutine runs continuously after setup finishes
ButtonPinState = digitalRead(ButtonPin); // read ButtonPin to ButtonPinState
if (MemVar == 0 || 255){ // first time an EEPROM is read it reads as 255
MemVar = 1;
}
if (ButtonPinState == HIGH){ // when ButtonPinState is HIGH...
++ PressDetects; // increment detection variable
}
if (PressDetects >= TriggerCount) { // when threshold is exceeded...
++ MemVar; // increment memory variable
PressDetects = 0; // reset button detector
if (MemVar >= 9){ // on 9th button press...
MemVar = 1; // reset color
}
EEPROM.write(MemoryLocation, MemVar); // write color to memory
if (MemVar == 8){ // on 8th button press...
RandomChoiceA = random(1, 2); // choose HIGH/LOW randomly
RandomChoiceB = random(1, 2); // choose HIGH/LOW randomly
RandomChoiceC = random(1, 2); // choose HIGH/LOW randomly
}
}
if (MemVar == 8){ // on 8th button press...
if (RandomChoiceA == 1){
digitalWrite(ColorOnePin, LOW);
else {
digitalWrite(ColorOnePin, HIGH);
}
if (RandomChoiceB == 1){
digitalWrite(ColorTwoPin, LOW);
else {
digitalWrite(ColorTwoPin, HIGH);
}
if (RandomChoiceC == 1){
digitalWrite(ColorThreePin, LOW);
else {
digitalWrite(ColorThreePin, HIGH);
}
}
else { // if MemVar != 0,8,9,10, or larger...
ColorChoice = MemVar;
}
if (ColorChoice == 1){
digitalWrite(ColorOnePin, HIGH);
digitalWrite(ColorTwoPin, HIGH);
digitalWrite(ColorThreePin, HIGH);
}
if (ColorChoice == 2){
digitalWrite(ColorOnePin, HIGH);
digitalWrite(ColorTwoPin, LOW);
digitalWrite(ColorThreePin, LOW);
}
if (ColorChoice == 3){
digitalWrite(ColorOnePin, HIGH);
digitalWrite(ColorTwoPin, HIGH);
digitalWrite(ColorThreePin, LOW);
}
if (ColorChoice == 4){
digitalWrite(ColorOnePin, LOW);
digitalWrite(ColorTwoPin, HIGH);
digitalWrite(ColorThreePin, LOW);
}
if (ColorChoice == 5){
digitalWrite(ColorOnePin, LOW);
digitalWrite(ColorTwoPin, HIGH);
digitalWrite(ColorThreePin, HIGH);
}
if (ColorChoice == 6){
digitalWrite(ColorOnePin, LOW);
digitalWrite(ColorTwoPin, LOW);
digitalWrite(ColorThreePin, HIGH);
}
if (ColorChoice == 7){
digitalWrite(ColorOnePin, HIGH);
digitalWrite(ColorTwoPin, LOW);
digitalWrite(ColorThreePin, HIGH);
}
}
// RHD's TTL Color Selector
// Programming by Matt "Sigurthr" Giordano 08/13/2014
// www.SigurthrEnterprises.com
// Sigurthr@SigurthrEnterprises.com
// ATTiny85 Physical Pinout - innermost designation is code addressable
// _______
// Reset _| |_| |_ Vcc
// ADC3 Pin3 3 _| |_ 2 Pin2 ADC1
// ADC2 Pin4 A2 _| ATT85 |_ 1 Pin1 Digital-1
// Gnd _| |_ 0 Pin0 Digital-0
// |_______|
#include <EEPROM.h> // include the EEPROM Memory library
int PressDetects = 0;
int ButtonPin = 3; // see pinout
int ColorOnePin = 0; // see pinout
int ColorTwoPin = 1; // see pinout
int ColorThreePin = 2; // see pinout
int MemVar;
int ButtonPinState;
int ColorChoice;
int MemoryLocation = 1;
unsigned int TriggerCount = 10; // threshold for debounce
void setup (){ // this subroutine runs once upon startup
MemVar = EEPROM.read(MemoryLocation); // read EEPROM on power on
pinMode (0, OUTPUT); // set pin 0 to output
pinMode (1, OUTPUT); // set pin 1 to output
pinMode (2, OUTPUT); // set pin 2 to output
pinMode (3, INPUT); // set pin 3 to input
}
void loop(){ // this subroutine runs continuously after setup finishes
ButtonPinState = digitalRead(ButtonPin); // read ButtonPin to ButtonPinState
if (MemVar == 0 || 255){ // first time an EEPROM is read it reads as 255
MemVar = 1;
}
if (ButtonPinState == HIGH){ // when ButtonPinState is HIGH...
++ PressDetects; // increment detection variable
}
if (PressDetects >= TriggerCount) { // when threshold is exceeded...
++ MemVar; // increment memory variable
PressDetects = 0; // reset button detector
if (MemVar >= 9){ // on 9th button press...
MemVar = 1; // reset color
}
if (MemVar == 8){ // on 8th button press...
ColorChoice = random(1, 7);
}
EEPROM.write(MemoryLocation, MemVar); // write color to memory
}
if (MemVar != 8){ // prevents ColorChoice from being set to 8 (invalid)
ColorChoice = MemVar;
}
if (ColorChoice == 1){
digitalWrite(ColorOnePin, HIGH);
digitalWrite(ColorTwoPin, HIGH);
digitalWrite(ColorThreePin, HIGH);
}
if (ColorChoice == 2){
digitalWrite(ColorOnePin, HIGH);
digitalWrite(ColorTwoPin, LOW);
digitalWrite(ColorThreePin, LOW);
}
if (ColorChoice == 3){
digitalWrite(ColorOnePin, HIGH);
digitalWrite(ColorTwoPin, HIGH);
digitalWrite(ColorThreePin, LOW);
}
if (ColorChoice == 4){
digitalWrite(ColorOnePin, LOW);
digitalWrite(ColorTwoPin, HIGH);
digitalWrite(ColorThreePin, LOW);
}
if (ColorChoice == 5){
digitalWrite(ColorOnePin, LOW);
digitalWrite(ColorTwoPin, HIGH);
digitalWrite(ColorThreePin, HIGH);
}
if (ColorChoice == 6){
digitalWrite(ColorOnePin, LOW);
digitalWrite(ColorTwoPin, LOW);
digitalWrite(ColorThreePin, HIGH);
}
if (ColorChoice == 7){
digitalWrite(ColorOnePin, HIGH);
digitalWrite(ColorTwoPin, LOW);
digitalWrite(ColorThreePin, HIGH);
}
}
// RHD's TTL Color Selector
// Programming by Matt "Sigurthr" Giordano 08/13/2014
// www.SigurthrEnterprises.com
// Sigurthr@SigurthrEnterprises.com
// ATTiny85 Physical Pinout - innermost designation is code addressable
// _______
// Reset _| |_| |_ Vcc
// ADC3 Pin3 3 _| |_ 2 Pin2 ADC1
// ADC2 Pin4 A2 _| ATT85 |_ 1 Pin1 Digital-1
// Gnd _| |_ 0 Pin0 Digital-0
// |_______|
#include <EEPROM.h> // include the EEPROM Memory library
byte PressDetects = 0;
byte ButtonPin = 3; // see pinout
byte ColorOnePin = 0; // see pinout
byte ColorTwoPin = 1; // see pinout
byte ColorThreePin = 2; // see pinout
byte MemVar;
byte ButtonPinState;
byte ColorChoice;
byte MemoryLocation = 1;
int TriggerCount = 10; // threshold for debounce
void setup (){ // this subroutine runs once upon startup
MemVar = EEPROM.read(MemoryLocation); // read EEPROM on power on
pinMode (0, OUTPUT); // set pin 0 to output
pinMode (1, OUTPUT); // set pin 1 to output
pinMode (2, OUTPUT); // set pin 2 to output
pinMode (3, INPUT); // set pin 3 to input
}
void loop(){ // this subroutine runs continuously after setup finishes
ButtonPinState = digitalRead(ButtonPin); // read ButtonPin to ButtonPinState
if (MemVar == 0 || 255){ // first time an EEPROM is read it reads as 255
MemVar = 1;
}
if (ButtonPinState == HIGH){ // when ButtonPinState is HIGH...
++ PressDetects; // increment detection variable
}
if (PressDetects >= TriggerCount) { // when threshold is exceeded...
++ MemVar; // increment memory variable
PressDetects = 0; // reset button detector
if (MemVar >= 9){ // on 9th button press...
MemVar = 1; // reset color
}
if (MemVar == 8){ // on 8th button press...
ColorChoice = random(1, 7);
}
EEPROM.write(MemoryLocation, MemVar); // write color to memory
}
switch (ColorChoice) {
case 1:
digitalWrite(ColorOnePin, HIGH);
digitalWrite(ColorTwoPin, HIGH);
digitalWrite(ColorThreePin, HIGH);
break;
case 2:
digitalWrite(ColorOnePin, HIGH);
digitalWrite(ColorTwoPin, LOW);
digitalWrite(ColorThreePin, LOW);
break;
case 3:
digitalWrite(ColorOnePin, HIGH);
digitalWrite(ColorTwoPin, HIGH);
digitalWrite(ColorThreePin, LOW);
break;
case 4:
digitalWrite(ColorOnePin, LOW);
digitalWrite(ColorTwoPin, HIGH);
digitalWrite(ColorThreePin, LOW);
break;
case 5:
digitalWrite(ColorOnePin, LOW);
digitalWrite(ColorTwoPin, HIGH);
digitalWrite(ColorThreePin, HIGH);
break;
case 6:
digitalWrite(ColorOnePin, LOW);
digitalWrite(ColorTwoPin, LOW);
digitalWrite(ColorThreePin, HIGH);
break;
case 7:
digitalWrite(ColorOnePin, HIGH);
digitalWrite(ColorTwoPin, LOW);
digitalWrite(ColorThreePin, HIGH);
break;
default:
ColorChoice = MemVar;
break;
}
}
// RHD's TTL Color Selector
// Programming by Matt "Sigurthr" Giordano 08/13/2014
// www.SigurthrEnterprises.com
// Sigurthr@SigurthrEnterprises.com
// ATTiny85 Physical Pinout - innermost designation is code addressable
// _______
// Reset _| |_| |_ Vcc
// ADC3 Pin3 3 _| |_ 2 Pin2 ADC1
// ADC2 Pin4 A2 _| ATT85 |_ 1 Pin1 Digital-1
// Gnd _| |_ 0 Pin0 Digital-0
// |_______|
#include <EEPROM.h> // include the EEPROM Memory library
boolean pinOptions[7][3] = { // Array of pin combinations (1 = on, 0 = off)
{1,1,1},
{1,0,0},
{1,1,0},
{0,1,0},
{0,1,1},
{0,0,1},
{1,0,1}
};
byte PressDetects = 0;
byte ButtonPin = 3; // see pinout
byte ColorOnePin = 0; // see pinout
byte ColorTwoPin = 1; // see pinout
byte ColorThreePin = 2; // see pinout
byte MemVar;
byte ButtonPinState;
byte ColorChoice;
byte MemoryLocation = 1;
byte TriggerCount = 10; // threshold for debounce
void setup (){ // this subroutine runs once upon startup
MemVar = EEPROM.read(MemoryLocation); // read EEPROM on power on
pinMode (0, OUTPUT); // set pin 0 to output
pinMode (1, OUTPUT); // set pin 1 to output
pinMode (2, OUTPUT); // set pin 2 to output
pinMode (3, INPUT); // set pin 3 to input
}
void loop(){ // this subroutine runs continuously after setup finishes
ButtonPinState = digitalRead(ButtonPin); // read ButtonPin to ButtonPinState
if (MemVar == 0 || 255){ // first time an EEPROM is read it reads as 255
MemVar = 1;
}
if (ButtonPinState == HIGH){ // when ButtonPinState is HIGH...
++ PressDetects; // increment detection variable
}
if (PressDetects >= TriggerCount) { // when threshold is exceeded...
++ MemVar; // increment memory variable
PressDetects = 0; // reset button detector
if (MemVar >= 9){ // on 9th button press...
MemVar = 1; // reset color
}
if (MemVar == 8){ // on 8th button press...
ColorChoice = random(1, 7);
}
EEPROM.write(MemoryLocation, MemVar); // write color to memory
}
if (MemVar != 8){ // prevents ColorChoice from being set to 8 (invalid)
ColorChoice = MemVar;
}
digitalWrite(ColorOnePin, pinOptions[ColorChoice-1][0]);
digitalWrite(ColorTwoPin, pinOptions[ColorChoice-1][1]);
digitalWrite(ColorThreePin, pinOptions[ColorChoice-1][2]);
}