I have a project where I need to make a coffee machine using C++ style code in Arduino UNO (meaning using only main and functions). What I want to know is how can I Initialize the LCD.
#include <LiquidCrystal_I2C.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <MsTimer2.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Globals
uint8_t flag = 1;
static unsigned long last_interrupt_time = 0;
/*
class LCD{
public:
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);
LCD () {
lcd.init();
lcd.backlight();
}
};
*/
class coff{
public:
void sui(){
switch (flag){
case 1:
flag++;
break;
}
}
};
ISR(INTO_vect){
if (millis() - last_interrupt_time > 200)
{
flag++;
}
last_interrupt_time = millis() ;
}
int main (void){
lcd.init();
lcd.clear();
lcd.backlight();
coff m;
// Rising edge of INTO generates interrupt
EICRA |= (1 << ISC01);
EICRA &= ~(1 << ISC00);
// Enable interrupts for INT0
EIMSK |= (1 <<INT0);
// Enable global interrupts
sei();
while(true){
m.sui();
}
}
I have an interrupt that you can ignore. I have tried to start the LCD in main, I also tried some class stuff which I commented out for now. But I really yeah don't know, and there is not much information that I could find on using the LCD in the way I want it. Let alone using C++ style code in Arduino
Hold on, what is wrong with the assignment ?
Arduino uses C++ code. When you just use main, then the Arduino software might not work well. Every Arduino function and every library depends on a working Arduino layer.
Does millis() work ? Does the I2C bus work ? I don't know. I have never seen something like this.
What you can do, is use the Uno board with the ATmega328P microcontroller and make a program with normal code. But you can not use any Arduino function and not any library that uses Arduino.
The website avrfreaks.net has nice projects and information how to use a ATmega328P (without Arduino).
You are either 100% in or 100% out the Arduino environment.
"function" is a wayyy to generalised term to define anything.
Each and every Arduino-library uses "functions". A part of the functions defined inside "classes" a part of them without "classes" but all are "functions"
So you have to do the same thing as with any software-project:
writing down very very precise information. Even the most advanced "fuzzy-logic" algorithm is based on very precise basic lines of code.