Display and buttons reading tested.

This commit is contained in:
Ricardo Work
2017-09-08 15:17:30 +00:00
parent 37ce2d7921
commit bb99dd6219
73 changed files with 130 additions and 25598 deletions

View File

@@ -7,25 +7,58 @@
*********************************************************************/
#include <SPI.h>
#include <Wire.h>
// Libraries to be included
//#include <SPI.h>
//#include <Wire.h>
#include <SoftwareSerial.h>
#include "Adafruit_GFX.h"
#include "Adafruit_SSD1306.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
#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
void setup() {
//Serial.begin(9600);
// 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);
@@ -38,11 +71,76 @@ void setup() {
// Since the buffer is intialized with an Adafruit splashscreen
// internally, this will display the splashscreen.
display.display();
delay(2000);
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);
@@ -51,19 +149,29 @@ void setup() {
display.drawPixel(109, 4, WHITE);
display.drawPixel(108, 3, WHITE);
display.drawPixel(108, 4, WHITE);
// Show the display buffer on the hardware.
// NOTE: You _must_ call display after making any drawing commands
// to make them visible on the display hardware!
display.display();
delay(2000);
//display.clearDisplay();
}
void loop() {
mySerial.println("TX working, yeaiii :)");
delay(5000);
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);
}