Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compatibility with AT90CAN128 #151

Open
JerryKomor opened this issue Sep 9, 2024 · 0 comments
Open

compatibility with AT90CAN128 #151

JerryKomor opened this issue Sep 9, 2024 · 0 comments

Comments

@JerryKomor
Copy link

JerryKomor commented Sep 9, 2024

I used the library on other controllers Atmega328, ATtiny85 and few others.
I'm working on new project and I need to have 11 buttons and having problems with the library compatibility with the processor. Using MCUdude MEGAcore library for the processor.
I have tried direct reading and writing to the ports and it works.

Any one had used the library with this micro, or maybe someone can see issues with my code. had it also shrunk down to 2 buttions

/*
*
*/

#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h> // bitmap https://learn.adafruit.com/1-8-tft-display?view=all
#include <SPI.h>

#include "OneButton.h" // https://github.com/mathertel/OneButton

//#define ENABLE_DEBUG
// 1.8" SPI LCD
#define TFT_CS 34 // PC6
#define TFT_RST 0 // 12 save reset pin -1
#define TFT_DC 35 // PC7
//Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC);

// Option 2: use any pins but a little slower!
//#define TFT_SCLK 13 // set these to be whatever pins you like!
//#define TFT_MOSI 11 // set these to be whatever pins you like!

#define OO 2 // PA0 on off switch
#define re_circ 3 // PA1 fresh air / re-circulate

int FAN_mtr = 6; // fan motor driver
int AC_comp = 26; // PG0/D26 AC compressor relay
int def_r = 27; // PG1/D27 rear defroster relay
int temp_l = A0; // PF0
int temp_r = A1; // PF1
int sun_lvl = A2; // PF2
int temp_evp = A3; // PF3

int flagDef = 0;
int flagTst = 0; //test
int buttonState = 0; // test

OneButton btn_OO(OO, true); //
OneButton btn_re_circ(re_circ, true); //

#include "Countimer.h" // https://github.com/inflop/Countimer
Countimer tDown;
int countDwn=0;
//String tmr = "";

void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("Starting Buttons...");
//
// link the button 1 functions.
Serial.println("setting I/O ports");
pinMode(LED_BUILTIN, OUTPUT); // PB5
pinMode(AC_comp, OUTPUT);
pinMode(def_r, OUTPUT);
pinMode(FAN_mtr, OUTPUT);
pinMode(temp_l, INPUT);
pinMode(temp_r, INPUT);
pinMode(sun_lvl, INPUT);
pinMode(temp_evp, INPUT);
digitalWrite(AC_comp, LOW);
digitalWrite(def_r, LOW);
digitalWrite(FAN_mtr, LOW);
Serial.println("setting up button ports");
pinMode(OO, INPUT);
pinMode(re_circ, INPUT);

btn_OO.attachClick(click_OO);
//btn_OO.attachDoubleClick(doubleclickO);
//btn_OO.attachLongPressStart(longPressStartO);
//btn_OO.attachLongPressStop(longPressStopO);
//btn_OO.attachDuringLongPress(longPressO);
btn_re_circ.attachClick(click_re_circ);

//
// display setup
tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab
tft.fillScreen(ST7735_BLACK);
tft.setRotation(2);
// Defrost timer 10min
tDown.setCounter(0, 10, 00, tDown.COUNT_DOWN, tDownComplete); // setup count down timer
//countDwn = (tDown.getCurrentTime()); // get current timer
//tDown.setInterval(print_tdown, 1000); // Call print_time2() method every 1s.
} // setup

// main code here, to run repeatedly:
void loop() {
//keep watching the buttons:
btn_OO.tick();
btn_re_circ.tick();

buttonState = digitalRead(OO);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(LED_BUILTIN, HIGH);
} else {
// turn LED off:
//digitalWrite(ledPin, LOW);
digitalWrite(LED_BUILTIN, LOW);
}

tDown.run();

} // loop

// ----- button callback functions -----
// This function will be called when the button1 was pressed 1 time (and no 2. button press followed).
void click_OO() {
Serial.println("btn - On/Off");
} // click_OO

// This function will be called when the button1 was pressed 2 times in a short timeframe.
void doubleclick_OO() {
// process loop
} // doubleclickO

// This function will be called once, when the button1 is pressed for a long time.
void longPressStart_OO() {
// process loop
} // longPressStartO

// This function will be called often, while the button1 is pressed for a long time.
void longPress_OO() {
// process loop
} // longPressO

// This function will be called once, when the button1 is released after beeing pressed for a long time.
void longPressStop_OO() {
// process loop
} // longPressStopO

void click_re_circ() {
Serial.println("btn - recirulate");
}

void click_def_R() {
Serial.println("btn - defrost Rear");
}
void click_def_F() {
Serial.println("btn - defrost Front");
}
void click_AC() {
Serial.println("btn - AC compressor");
}
void click_mde() {
Serial.println("btn - mode");
}
void click_md_auto() {
Serial.println("btn - mode Auto");
}
void click_t_up() {
Serial.println("btn - temp UP");
}
void click_t_dwn() {
Serial.println("btn - temp DOWN");
}
void click_fn_up() {
Serial.println("btn - fan faster");
}
void click_fn_dwn() {
Serial.println("btn - fan slower");
}

void tDownComplete(){
Serial.println(" defrost finish");
digitalWrite(def_r, LOW);
flagDef=0; //change flag variable again
tDown.stop();
//tft.fillRect(80,135,43,13,ST7735_BLACK);
}

//end --------------------------------------------------------------------

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant