178 lines
4.3 KiB
C++
Executable File
178 lines
4.3 KiB
C++
Executable File
/*********************************************************************
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*********************************************************************/
|
|
|
|
// Libraries to be included
|
|
//#include <SPI.h>
|
|
//#include <Wire.h>
|
|
#include <SoftwareSerial.h>
|
|
#include <Adafruit_GFX.h>
|
|
#include <Adafruit_SSD1306.h>
|
|
|
|
#define OLED_RESET 8
|
|
Adafruit_SSD1306 display(OLED_RESET);
|
|
|
|
// 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 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
|
|
|
|
volatile byte state = LOW;
|
|
|
|
// 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() {
|
|
|
|
// 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
|
|
|
|
// 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
|
|
digitalWrite(led2,HIGH); // Turn off led 2
|
|
|
|
// set the data rate for the SoftwareSerial port
|
|
mySerial.begin(9600);
|
|
|
|
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
|
|
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
|
|
// init done
|
|
|
|
// 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
|
|
|
|
// 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.setTextColor(WHITE);
|
|
// display.setCursor(0,8);
|
|
// display.println("Hello, world!");
|
|
// display.display();
|
|
// delay(2000);
|
|
// display.clearDisplay();
|
|
|
|
// mySerial.println("TX working, yeaiii :), stilll");
|
|
// delay(5000);
|
|
}
|
|
|
|
|
|
void batt_icon (void) {
|
|
|
|
// Draw the battery icon
|
|
display.drawRect(111, 1, 16, 6, WHITE);
|
|
display.drawPixel(110, 3, WHITE);
|
|
display.drawPixel(110, 4, WHITE);
|
|
display.drawPixel(109, 3, WHITE);
|
|
display.drawPixel(109, 4, WHITE);
|
|
display.drawPixel(108, 3, WHITE);
|
|
display.drawPixel(108, 4, WHITE);
|
|
display.display();
|
|
}
|
|
|
|
void sw1_press() {
|
|
digitalWrite(led1, HIGH);
|
|
digitalWrite(led2, HIGH);
|
|
digitalWrite(led1, LOW);
|
|
}
|
|
|
|
void sw2_press() {
|
|
digitalWrite(led1, HIGH);
|
|
digitalWrite(led2, HIGH);
|
|
digitalWrite(led2, LOW);
|
|
}
|
|
|
|
void sw3_press() {
|
|
digitalWrite(led1, HIGH);
|
|
digitalWrite(led2, HIGH);
|
|
digitalWrite(led1, LOW);
|
|
}
|
|
|
|
void sw4_press() {
|
|
digitalWrite(led1, HIGH);
|
|
digitalWrite(led2, HIGH);
|
|
digitalWrite(led2, LOW);
|
|
}
|