Version 0.2.0: EEPROM is no longer beta. Beta deleted.
							parent
							
								
									7ff748af1b
								
							
						
					
					
						commit
						264f4198ce
					
				@ -1,127 +0,0 @@
 | 
				
			||||
/*
 | 
				
			||||
  HiFiLOGIX EEROM BETA 0.1.9 
 | 
				
			||||
  
 | 
				
			||||
  dewdude@gmail.com - 09-JAN-2019
 | 
				
			||||
 | 
				
			||||
   !!! IMPORTANT !!!
 | 
				
			||||
  
 | 
				
			||||
  IF YOU HAVE DATA AT ADDRESSES 1020 - 1023, THIS SKETCH WILL CHANGE IT.
 | 
				
			||||
  
 | 
				
			||||
  IF YOUR EEPROM IS SMALLER, YOU WILL NEED TO CHANGE THE ADDRESSES.
 | 
				
			||||
  
 | 
				
			||||
  THIS CURRENTLY WRITES TO THE EEPROM EVERY SOURCE CHANGE.
 | 
				
			||||
  
 | 
				
			||||
  Address 1020 stores the byte to be sent to the shift register.
 | 
				
			||||
  Address 1021 stores the x offset for the display.
 | 
				
			||||
  Address 1022 contains the index of the input string array.
 | 
				
			||||
  Address 1023 contains the letter "T" if defaults exist.
 | 
				
			||||
  
 | 
				
			||||
  On boot the script looks for the letter "T" at address 1023.
 | 
				
			||||
  If it exists this is supposed to indicate it's been initialized
 | 
				
			||||
  and it will continue with the main setup loop. If not, it writes
 | 
				
			||||
  default values to locations 1020 - 1022 and writes T to 1023.
 | 
				
			||||
  
 | 
				
			||||
  During the setup loop, the values stored at 1020 - 1022 are
 | 
				
			||||
  fed as arguments to DontCrossTheStreams. I could probably do
 | 
				
			||||
  this with a bunch of if loops to read a single byte and translate
 | 
				
			||||
  that in to the rest...but I don't know how that would affect the
 | 
				
			||||
  memory.
 | 
				
			||||
  
 | 
				
			||||
 */
 | 
				
			||||
#include <Wire.h>
 | 
				
			||||
#include <U8g2lib.h>
 | 
				
			||||
#include <IRremote.h>
 | 
				
			||||
#include <avr/pgmspace.h> 
 | 
				
			||||
#include <EEPROM.h>
 | 
				
			||||
#define di 1022
 | 
				
			||||
#define dx 1021
 | 
				
			||||
#define db 1020
 | 
				
			||||
#define dt 1023
 | 
				
			||||
#include "logo.h" // XBMP data for logo.
 | 
				
			||||
 | 
				
			||||
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE); 
 | 
				
			||||
 | 
				
			||||
const char in0[] PROGMEM = "TAPE-2";
 | 
				
			||||
const char in1[] PROGMEM = "TAPE-1";
 | 
				
			||||
const char in2[] PROGMEM = "AUX";
 | 
				
			||||
const char in3[] PROGMEM = "TUNER";
 | 
				
			||||
const char in4[] PROGMEM = "PHONO-1";
 | 
				
			||||
const char in5[] PROGMEM = "PHONO-2";
 | 
				
			||||
 | 
				
			||||
const char * const inputs[] PROGMEM ={in0,in1,in2,in3,in4,in5}; // Drop the entire array in to program space.
 | 
				
			||||
 | 
				
			||||
int latchPin = 11;
 | 
				
			||||
int clockPin = 9;
 | 
				
			||||
int dataPin = 12;
 | 
				
			||||
int IRin = 7;
 | 
				
			||||
int blanking = 5;
 | 
				
			||||
int matrix = A0;
 | 
				
			||||
IRrecv remote(IRin);
 | 
				
			||||
decode_results ircode;
 | 
				
			||||
char txt[8];
 | 
				
			||||
 | 
				
			||||
void DontCrossTheStreams(byte op, int x, int i)             // There's something very important I forgot to tell you.
 | 
				
			||||
{                                                           // Don't cross the streams.
 | 
				
			||||
    strcpy_P(txt, (char*)pgm_read_word(&(inputs[i])));      // Why?
 | 
				
			||||
    digitalWrite(latchPin, LOW);                            // It would be bad.
 | 
				
			||||
    shiftOut(dataPin, clockPin, LSBFIRST, op);              // What do you mean, bad?
 | 
				
			||||
    digitalWrite(latchPin, HIGH);                           // Imagine all life as you know
 | 
				
			||||
    u8g2.clearBuffer();                                     // it stopping instaneously
 | 
				
			||||
    u8g2.drawStr(x,30,txt);                                 // and every molecule in
 | 
				
			||||
    u8g2.sendBuffer();                                      // your body exploding
 | 
				
			||||
    EEPROM.update(db, op);                                  // at the speed of light.
 | 
				
			||||
    EEPROM.update(dx, x);                                   // Total protonic reversal.
 | 
				
			||||
    EEPROM.update(di, i);                                   // That's bad.
 | 
				
			||||
}                                                           // Important safety tip, thanks Egon.
 | 
				
			||||
 | 
				
			||||
 | 
				
			||||
 | 
				
			||||
void eeprominit() {                                         // This checks the EEPROM to see if it's
 | 
				
			||||
                                                            // been initialized by the code before.
 | 
				
			||||
if (EEPROM.read(dt) == 'T') {                               // Check address 1023 for init flag "T"
 | 
				
			||||
    return;
 | 
				
			||||
  } else {
 | 
				
			||||
    EEPROM.write(db, 16);
 | 
				
			||||
    EEPROM.write(dx, 32);
 | 
				
			||||
    EEPROM.write(di, 2);
 | 
				
			||||
    EEPROM.write(dt, 'T');
 | 
				
			||||
  }
 | 
				
			||||
}
 | 
				
			||||
 | 
				
			||||
void setup()
 | 
				
			||||
{
 | 
				
			||||
  pinMode(latchPin, OUTPUT);
 | 
				
			||||
  pinMode(dataPin, OUTPUT);  
 | 
				
			||||
  pinMode(clockPin, OUTPUT);
 | 
				
			||||
  pinMode(blanking, OUTPUT);
 | 
				
			||||
  eeprominit();
 | 
				
			||||
  u8g2.begin();
 | 
				
			||||
  remote.enableIRIn();
 | 
				
			||||
  u8g2.firstPage();                       // Logo is now bitmapped and since I only call it
 | 
				
			||||
    do {                                  // once, it doesn't need it's own function.
 | 
				
			||||
    u8g2.drawXBMP(14,4,hifilogix_width,hifilogix_height,hifilogix_bits);
 | 
				
			||||
    } while ( u8g2.nextPage() );
 | 
				
			||||
  delay(2000);                            // It takes the Denon about 4.5 seconds to kick speakers on.
 | 
				
			||||
  u8g2.setFont(u8g2_font_logisoso28_tr);  
 | 
				
			||||
  DontCrossTheStreams(EEPROM.read(db),EEPROM.read(dx),EEPROM.read(di));  // THIS IS NO LONGER STATIC IN THE BETA! (yay.)
 | 
				
			||||
  //DontCrossTheStreams(16,32,2);
 | 
				
			||||
  digitalWrite(blanking,HIGH);            // Now drives a logic inverter.
 | 
				
			||||
}
 | 
				
			||||
 | 
				
			||||
void loop()
 | 
				
			||||
{
 | 
				
			||||
int mx = analogRead(matrix);
 | 
				
			||||
byte icode = 0;                           // I changed how I handed the inputs.
 | 
				
			||||
if (remote.decode(&ircode)) {
 | 
				
			||||
    icode = ircode.value;
 | 
				
			||||
    remote.resume();    
 | 
				
			||||
}
 | 
				
			||||
// I don't know if it improves things, but I sure like how much smaller this section is.
 | 
				
			||||
if ((mx > 100 && mx < 200) || (icode == 0x97)) DontCrossTheStreams(64,10,0); // The code I originally used to figure out my
 | 
				
			||||
if ((mx > 500 && mx < 600) || (icode == 0x67)) DontCrossTheStreams(32,10,1); // remote codes returned 3 bytes in hex. I can't 
 | 
				
			||||
if ((mx > 900 && mx < 950) || (icode == 0x4F)) DontCrossTheStreams(16,32,2); // remember what that code was, but I only need 
 | 
				
			||||
if ((mx > 1000)            || (icode == 0xCF)) DontCrossTheStreams(8,18,3);  // the last bit with the remote I'm using. 
 | 
				
			||||
if ((mx > 820 && mx < 899) || (icode == 0xE7)) DontCrossTheStreams(6,1,4);   // I'm working on making the bare-bones utility I
 | 
				
			||||
if ((mx > 700 && mx < 800) || (icode == 0x85)) DontCrossTheStreams(5,1,5);   // wrote a bit more user-friendly.
 | 
				
			||||
delay(200);
 | 
				
			||||
}
 | 
				
			||||
					Loading…
					
					
				
		Reference in New Issue