I am trying to make a remote for my sat receiver.
The channel upcode works, but then when I insert the code to read my push buttons it will not.
I have even put the upcode command before my “GetBtn” routine.
I have tried serial printing all of the timer registers to see if anything is going wrong here.
Here is my code::-
/*********************************************************************
TV remote for edision sat reciever
Uses:-
Nokia 3310 display, ProMini running at 16mhz and 2 pencels, 3.1V - might be borderline!
ledpin needs to be earthed on my display (pinouts diff order too)
leds seem to light ok with 400 ohm (prob 6 mA on 3V)
Contrast setting: Ada set it to 50.
40 I see nothing
60 v good contrast without backlight (daytime no better with backlight)
IR led with 75R for 3V
Pins:-
DO:-
settings menu - at mo hitting ok on settings will prob crash
backlight code
*********************************************************************/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
//#include "Edision.h"
#define BLDelay 120 // backlight on time
#define MenuMax 8
static int BLPin = 2; // these were all byte, but reference says should be int
static int BtnNxtPin = 9; // 9
static int BtnOkPin = 8; // 8
static int IRledPin = 13;
byte BtnNxt = 0;
byte BtnOk = 0;
byte MenuIndex = 1;
byte BLTimer = 0;
Adafruit_PCD8544 display = Adafruit_PCD8544(3, 4, 5, 6, 7);
// display pins clk Din D/C CS RST
void setup() {
Serial.begin(9600);
pinMode(IRledPin, OUTPUT);
pinMode(BLPin, OUTPUT); // £ set low for on
pinMode(BtnNxtPin,INPUT_PULLUP);
pinMode(BtnOkPin,INPUT_PULLUP);
digitalWrite(BLPin,LOW);
display.begin(); // init done
display.setContrast(60); // orig Ada setting is 50
display.clearDisplay(); // clear the screen and buffer
XChnUp(); // *** this works provided I comment out GetBtn function below!
}
void loop() {
GetBtn(); // *** this makes above work!
Menu();
Display();
delay(200);
}
// ************************************* FUNCTIONS *************************************************************
void GetBtn() {
BtnNxt = 0; BtnOk = 0;
// if(digitalRead(BtnNxtPin) == 0) BtnNxt = 1; if(digitalRead(BtnOkPin) == 0) BtnOk = 1;
if(BtnNxt == 1 || BtnOk == 1) BLTimer = BLDelay;
// do { /*wait for button release */} while (digitalRead(BtnNxtPin) == 0 || digitalRead(BtnOkPin) == 0);
delay(10); //debounce
}
void Menu() {
if (BtnNxt == 1) MenuIndex ++; if (MenuIndex > MenuMax) MenuIndex = 1;
// if ((BtnOk == 1) && (MenuIndex < 8)) TxCode(); // which code Txd is based on MenuIndex
if ((BtnOk == 1) && (MenuIndex == 2)) XChnUp(); // which code Txd is based on MenuIndex
}
void Display() {
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(BLACK);
switch(MenuIndex) {
case 1:
display.println(F("Power"));
break;
case 2:
display.println(F("Chn Up")); display.print(F("Cur Up"));
break;
case 3:
display.println(F("Chn Dn")); display.print(F("Cur Dn"));
break;
case 4:
display.println(F("Vol Up")); display.print(F("Cur R"));
break;
case 5:
display.println(F("Vol Dn")); display.print(F("Cur L"));
break;
case 6:
display.println(F("Info"));
break;
case 7:
display.println(F("OK"));
break;
case 8:
display.println(F("Settngs"));
break;
}
display.display();
}
void TxCode() {
byte CodeIdx = MenuIndex - 1;
for (int i=0; i <= 66; i++){ // £ 67?
pulseIR(EdCode[CodeIdx][i]);
i++; // this gets 67th element on final loop = 68th item
delayMicroseconds(EdCode[CodeIdx][i]);
}
}
void pulseIR(long microsecs) { // count down from the number of microseconds we are told to wait
cli(); // this turns off any background interrupts
while (microsecs > 0) { // 38 kHz is about 13 microseconds high and 13 microseconds low
digitalWrite(IRledPin, HIGH); // this takes about 3 microseconds to happen
delayMicroseconds(10); // hang out for 10 microseconds
digitalWrite(IRledPin, LOW); // this also takes about 3 microseconds
delayMicroseconds(10); // hang out for 10 microseconds
// so 26 microseconds altogether
microsecs -= 26;
}
sei(); // this turns them back on
}
void XChnUp() {
pulseIR(9240);delayMicroseconds(4620);
pulseIR(560);delayMicroseconds(540);
pulseIR(600);delayMicroseconds(540);
pulseIR(600);delayMicroseconds(540);
pulseIR(580);delayMicroseconds(540);
pulseIR(600);delayMicroseconds(540);
pulseIR(580);delayMicroseconds(560);
pulseIR(580);delayMicroseconds(540);
pulseIR(600);delayMicroseconds(540);
pulseIR(580);delayMicroseconds(1740);
pulseIR(560);delayMicroseconds(1740);
pulseIR(540);delayMicroseconds(1740);
pulseIR(580);delayMicroseconds(1720);
pulseIR(560);delayMicroseconds(1740);
pulseIR(560);delayMicroseconds(1740);
pulseIR(560);delayMicroseconds(1720);
pulseIR(580);delayMicroseconds(1720);
pulseIR(560);delayMicroseconds(540);
pulseIR(600);delayMicroseconds(1740);
pulseIR(560);delayMicroseconds(1720);
pulseIR(560);delayMicroseconds(580);
pulseIR(560);delayMicroseconds(540);
pulseIR(600);delayMicroseconds(540);
pulseIR(580);delayMicroseconds(540);
pulseIR(600);delayMicroseconds(540);
pulseIR(600);delayMicroseconds(1720);
pulseIR(560);delayMicroseconds(580);
pulseIR(560);delayMicroseconds(560);
pulseIR(560);delayMicroseconds(1740);
pulseIR(560);delayMicroseconds(1820);
pulseIR(480);delayMicroseconds(1760);
pulseIR(540);delayMicroseconds(1800);
pulseIR(500);delayMicroseconds(1840);
pulseIR(440);delayMicroseconds(50000);
//Serial.println("here 2 ");
}
// END
I have tried tried to highlight the code and use the code symbol at top of page, but I can not highlight it - sorry.
This is what happens:-
If I comment out the two lines where I digitalread (lines 71 and 73), then when I transmit the code (at the end of SetUp, line 56, “XChnUp” the sat receiver goes up one channel.
If I uncomment the digitalread (so I can check my button state), then I see nothing at the IR led when I look at it with my camera.
Any help would be appreciated! Thank you