Working on menus.
This commit is contained in:
@@ -17,44 +17,46 @@
|
||||
#define OLED_RESET 8
|
||||
Adafruit_SSD1306 display(OLED_RESET);
|
||||
|
||||
#define ON 0 // ON means pin is on GND
|
||||
#define OFF 1 // OFF means pin is on VCC
|
||||
|
||||
// Assign switches and led's to arduino pins
|
||||
#define SW1 2 // Switch 1 connected to arduino pin 2
|
||||
#define SW2 3 // Switch 1 connected to arduino pin 3
|
||||
#define SW3 4 // Switch 1 connected to arduino pin 4
|
||||
#define SW4 5 // Switch 1 connected to arduino pin 5
|
||||
#define UP 2 // Switch 1 will be function UP connected to arduino pin 2
|
||||
#define OK 3 // Switch 2 will be function OK connected to arduino pin 3
|
||||
#define DOWN 4 // Switch 3 will be function DOWN connected to arduino pin 4
|
||||
#define CANCEL 5 // Switch 4 will be function CANCEL connected to arduino pin 5
|
||||
#define led1 9 // Led 1 connected to arduino pin 9
|
||||
#define led2 10 // Led 2 connected to arduino pin 10
|
||||
|
||||
// Macros to read the switchs
|
||||
#define rSW1 digitalRead(SW1) // Read switch 1
|
||||
#define rSW2 digitalRead(SW2) // Read switch 2
|
||||
#define rSW3 digitalRead(SW3) // Read switch 3
|
||||
#define rSW4 digitalRead(SW4) // Read switch 4
|
||||
#define rUP digitalRead(UP) // Read button UP state
|
||||
#define rOK digitalRead(OK) // Read button OK state
|
||||
#define rDOWN digitalRead(DOWN) // Read button DOWN state
|
||||
#define rCANCEL digitalRead(CANCEL) // Read button CANCEL state
|
||||
|
||||
volatile byte state = LOW;
|
||||
//volatile byte state = LOW;
|
||||
|
||||
// Variables creation
|
||||
int menuState = 0; // Integer with the number of the menu you are in
|
||||
int UP_state = OFF; // Holds state for UP, either ON or OFF
|
||||
int OK_state = OFF; // Holds state for OK, either ON or OFF
|
||||
int DOWN_state = OFF; // Holds state for DOWN, either ON or OFF
|
||||
int CANCEL_state = OFF; // Holds state for CANCEL, either ON or OFF
|
||||
|
||||
// Create an integer with the number of the menu you are in
|
||||
int menuState = 0;
|
||||
|
||||
// Create SoftwareSerial object and designate pins
|
||||
SoftwareSerial mySerial(6, 7); // RX, TX
|
||||
|
||||
void setup() {
|
||||
void setup() { // BEGIN SETUP ------------------------------------
|
||||
|
||||
// Configure buttons and led's has inputs or outputs
|
||||
pinMode(led1, OUTPUT); // Led 1 is an output
|
||||
pinMode(led2, OUTPUT); // Led 2 is an output
|
||||
pinMode(SW1, INPUT); // Switch 1 is an input
|
||||
pinMode(SW2, INPUT); // Switch 2 is an input
|
||||
pinMode(SW3, INPUT); // Switch 3 is an input
|
||||
pinMode(SW4, INPUT); // Switch 4 is an input
|
||||
pinMode(UP, INPUT); // Switch 1 is an input
|
||||
pinMode(OK, INPUT); // Switch 2 is an input
|
||||
pinMode(DOWN, INPUT); // Switch 3 is an input
|
||||
pinMode(CANCEL, INPUT); // Switch 4 is an input
|
||||
|
||||
// Interrupts
|
||||
// If Switch X on change state
|
||||
attachInterrupt(digitalPinToInterrupt(SW1), sw1_press, CHANGE);
|
||||
attachInterrupt(digitalPinToInterrupt(SW2), sw2_press, CHANGE);
|
||||
attachInterrupt(digitalPinToInterrupt(SW3), sw3_press, CHANGE);
|
||||
attachInterrupt(digitalPinToInterrupt(SW4), sw4_press, CHANGE);
|
||||
|
||||
// Define the starting state of the led's
|
||||
digitalWrite(led1,HIGH); // Turn off led 1
|
||||
@@ -70,72 +72,77 @@ void setup() {
|
||||
// Show image buffer on the display hardware.
|
||||
// Since the buffer is intialized with an Adafruit splashscreen
|
||||
// internally, this will display the splashscreen.
|
||||
display.display();
|
||||
delay(2000); // Wait 2 seconds
|
||||
//display.display();
|
||||
//delay(2000); // Wait 2 seconds
|
||||
|
||||
|
||||
// initialize timer1 ---------------------------------------
|
||||
noInterrupts(); // disable all interrupts
|
||||
TCCR1A = 0;
|
||||
TCCR1B = 0;
|
||||
TCNT1 = 0;
|
||||
|
||||
OCR1A = 9000; // Load value to compare
|
||||
TCCR1B |= (1 << WGM12); // CTC mode
|
||||
TCCR1B |= (1 << CS10); // 64 prescaler
|
||||
TCCR1B |= (1 << CS11); //
|
||||
TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt
|
||||
interrupts(); // enable all interrupts
|
||||
// ----------------------------------------------------------
|
||||
|
||||
|
||||
// Clear the buffer.
|
||||
display.clearDisplay();
|
||||
|
||||
display.setTextSize(2);
|
||||
display.setTextColor(WHITE);
|
||||
display.setCursor(36,12);
|
||||
display.println("NMM-1");
|
||||
display.display();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
batt_icon();
|
||||
|
||||
|
||||
/* if (!rSW1) {
|
||||
digitalWrite(led1, LOW);
|
||||
delay(300);
|
||||
digitalWrite(led1, HIGH);
|
||||
}
|
||||
|
||||
else if (!rSW2) {
|
||||
digitalWrite(led2, LOW);
|
||||
delay(300);
|
||||
digitalWrite(led2, HIGH);
|
||||
}
|
||||
|
||||
else if (!rSW3) {
|
||||
digitalWrite(led1, LOW);
|
||||
digitalWrite(led2, LOW);
|
||||
delay(300);
|
||||
digitalWrite(led1, HIGH);
|
||||
digitalWrite(led2, HIGH);
|
||||
}
|
||||
|
||||
else if (!rSW4) {
|
||||
|
||||
for (int i = 10; i > 0; i--) {
|
||||
digitalWrite(led1, LOW);
|
||||
digitalWrite(led2, HIGH);
|
||||
delay(400);
|
||||
digitalWrite(led1, HIGH);
|
||||
digitalWrite(led2, LOW);
|
||||
delay(400);
|
||||
}
|
||||
digitalWrite(led1, HIGH);
|
||||
digitalWrite(led2, HIGH);
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
// display.setTextSize(1);
|
||||
// display.setTextSize(2);
|
||||
// display.setTextColor(WHITE);
|
||||
// display.setCursor(0,8);
|
||||
// display.println("Hello, world!");
|
||||
// display.setCursor(36,12);
|
||||
// display.println("NMM-1");
|
||||
// display.display();
|
||||
// delay(2000);
|
||||
// display.clearDisplay();
|
||||
// display.display();
|
||||
|
||||
|
||||
} // END SETUP --------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// Timer compare interrupt service routine --------------------------
|
||||
ISR(TIMER1_COMPA_vect) // Here we chose between the blinker sequence
|
||||
{ // or to show the temperature on the LEDs
|
||||
|
||||
|
||||
if (!rUP && menuState < 2) {
|
||||
menuState++;
|
||||
}
|
||||
if (!rDOWN && menuState > 1) {
|
||||
menuState--;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
void loop() {
|
||||
//digitalWrite(led2, !digitalRead(led2)); // toggle state
|
||||
batt_icon();
|
||||
|
||||
if (menuState == 1) {
|
||||
one();
|
||||
}
|
||||
else if (menuState == 2) {
|
||||
two();
|
||||
}
|
||||
else {
|
||||
zero();
|
||||
}
|
||||
|
||||
|
||||
// mySerial.println("TX working, yeaiii :), stilll");
|
||||
// delay(5000);
|
||||
}
|
||||
|
||||
|
||||
@@ -152,26 +159,46 @@ void batt_icon (void) {
|
||||
display.display();
|
||||
}
|
||||
|
||||
void sw1_press() {
|
||||
digitalWrite(led1, HIGH);
|
||||
digitalWrite(led2, HIGH);
|
||||
digitalWrite(led1, LOW);
|
||||
void zero (void) {
|
||||
|
||||
display.drawRect(0, 8, 168, 24, BLACK);
|
||||
display.display();
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(WHITE);
|
||||
display.setCursor(0,12);
|
||||
display.println("Read NMEA0183");
|
||||
display.setCursor(0,22);
|
||||
display.println("Write NMEA0183");
|
||||
display.display();
|
||||
|
||||
}
|
||||
|
||||
void sw2_press() {
|
||||
digitalWrite(led1, HIGH);
|
||||
digitalWrite(led2, HIGH);
|
||||
digitalWrite(led2, LOW);
|
||||
void one (void) {
|
||||
|
||||
display.drawRect(0, 8, 168, 24, BLACK);
|
||||
display.display();
|
||||
display.clearDisplay();
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(WHITE);
|
||||
display.setCursor(0,12);
|
||||
display.println("Read NMEA0183");
|
||||
display.setCursor(0,22);
|
||||
display.println("Write NMEA0183 <--");
|
||||
display.display();
|
||||
|
||||
}
|
||||
|
||||
void sw3_press() {
|
||||
digitalWrite(led1, HIGH);
|
||||
digitalWrite(led2, HIGH);
|
||||
digitalWrite(led1, LOW);
|
||||
}
|
||||
void two (void) {
|
||||
|
||||
display.drawRect(0, 8, 168, 24, BLACK);
|
||||
display.display();
|
||||
display.clearDisplay();
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(WHITE);
|
||||
display.setCursor(0,12);
|
||||
display.println("Read NMEA0183 <--");
|
||||
display.setCursor(0,22);
|
||||
display.println("Write NMEA0183");
|
||||
display.display();
|
||||
|
||||
void sw4_press() {
|
||||
digitalWrite(led1, HIGH);
|
||||
digitalWrite(led2, HIGH);
|
||||
digitalWrite(led2, LOW);
|
||||
}
|
||||
|
Reference in New Issue
Block a user