Initial commit
This commit is contained in:
		
							
								
								
									
										71
									
								
								firmware/display/display.ino
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								firmware/display/display.ino
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,71 @@
 | 
			
		||||
#include <SPI.h>
 | 
			
		||||
#include <Wire.h>
 | 
			
		||||
#include <Adafruit_GFX.h>
 | 
			
		||||
#include <Adafruit_SSD1306.h>
 | 
			
		||||
 | 
			
		||||
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire);
 | 
			
		||||
 | 
			
		||||
int setPoint = 69;
 | 
			
		||||
 | 
			
		||||
#define BUTTON_A  31
 | 
			
		||||
#define BUTTON_B  30
 | 
			
		||||
#define BUTTON_C  27
 | 
			
		||||
 | 
			
		||||
void setup() {
 | 
			
		||||
  Serial.begin(9600);
 | 
			
		||||
 | 
			
		||||
  Serial.println("OLED FeatherWing test");
 | 
			
		||||
  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
 | 
			
		||||
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32
 | 
			
		||||
 | 
			
		||||
  Serial.println("OLED begun");
 | 
			
		||||
 | 
			
		||||
  // 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(1000);
 | 
			
		||||
 | 
			
		||||
  // Clear the buffer.
 | 
			
		||||
  display.clearDisplay();
 | 
			
		||||
  display.display();
 | 
			
		||||
 | 
			
		||||
  Serial.println("IO test");
 | 
			
		||||
 | 
			
		||||
  pinMode(BUTTON_A, INPUT_PULLUP);
 | 
			
		||||
  pinMode(BUTTON_B, INPUT_PULLUP);
 | 
			
		||||
  pinMode(BUTTON_C, INPUT_PULLUP);
 | 
			
		||||
 | 
			
		||||
  // text display tests
 | 
			
		||||
  display.setTextSize(3);
 | 
			
		||||
  display.setTextColor(SSD1306_WHITE);
 | 
			
		||||
  display.setCursor(0,0);
 | 
			
		||||
  //display.print("Connecting to SSID\n'adafruit':");
 | 
			
		||||
  //display.print("connected!");
 | 
			
		||||
  //display.println("IP: 10.0.1.23");
 | 
			
		||||
  display.println("Boot");
 | 
			
		||||
  display.setCursor(0,0);
 | 
			
		||||
  display.display(); // actually display all of the above
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loop() {
 | 
			
		||||
 | 
			
		||||
  if (!digitalRead(BUTTON_A)) {
 | 
			
		||||
    setPoint++;
 | 
			
		||||
  } else if (!digitalRead(BUTTON_C)) {
 | 
			
		||||
    setPoint--;
 | 
			
		||||
  } else if (!digitalRead(BUTTON_B)) {
 | 
			
		||||
    ; // GO!
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  delay(50);
 | 
			
		||||
 | 
			
		||||
  display.clearDisplay();
 | 
			
		||||
 | 
			
		||||
  display.setCursor(0,0);
 | 
			
		||||
  display.print(setPoint);
 | 
			
		||||
  display.println(" PSI");
 | 
			
		||||
  
 | 
			
		||||
  yield();
 | 
			
		||||
  display.display();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										164
									
								
								firmware/main/main.ino
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										164
									
								
								firmware/main/main.ino
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,164 @@
 | 
			
		||||
#include <Wire.h>
 | 
			
		||||
#include <Adafruit_GFX.h>
 | 
			
		||||
#include <Adafruit_SSD1306.h>
 | 
			
		||||
#include <Adafruit_FeatherOLED.h>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define DEBUG 0
 | 
			
		||||
 | 
			
		||||
#define BUTTON_HOLD_TIME 500
 | 
			
		||||
#define BUTTON_PRESS_TIME 20
 | 
			
		||||
 | 
			
		||||
#define UP_BUTTON 31
 | 
			
		||||
#define ENTER_BUTTON 30
 | 
			
		||||
#define DOWN_BUTTON 27
 | 
			
		||||
 | 
			
		||||
Adafruit_FeatherOLED oled = Adafruit_FeatherOLED();
 | 
			
		||||
 | 
			
		||||
static const unsigned char PROGMEM arrow[] =
 | 
			
		||||
{ B10000000,
 | 
			
		||||
  B11000000,
 | 
			
		||||
  B11100000,
 | 
			
		||||
  B11000000,
 | 
			
		||||
  B10000000};
 | 
			
		||||
//oled.drawBitmap(0, 1, arrow, 8, 5, 1);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
enum buttonStates {
 | 
			
		||||
	OPEN,
 | 
			
		||||
	CLOSED,
 | 
			
		||||
	CHECK_PRESSED,
 | 
			
		||||
	PRESSED,
 | 
			
		||||
	HELD,
 | 
			
		||||
	NUM_BUTTONSTATES
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum screenStates {
 | 
			
		||||
	PRESSURE,
 | 
			
		||||
	SETTINGS,
 | 
			
		||||
	NUM_SCREENSTATES
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum buttonStates upButton = OPEN;
 | 
			
		||||
enum buttonStates enterButton = OPEN;
 | 
			
		||||
enum buttonStates downButton = OPEN;
 | 
			
		||||
 | 
			
		||||
int pressureSetPoint = 69;
 | 
			
		||||
 | 
			
		||||
void setup()
 | 
			
		||||
{
 | 
			
		||||
  Serial.begin(115200);
 | 
			
		||||
 | 
			
		||||
  oled.init();
 | 
			
		||||
 | 
			
		||||
  pinMode(UP_BUTTON, INPUT_PULLUP);
 | 
			
		||||
  pinMode(ENTER_BUTTON, INPUT); // Has external pullup
 | 
			
		||||
  pinMode(DOWN_BUTTON, INPUT_PULLUP);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loop() {
 | 
			
		||||
	pollButtons();
 | 
			
		||||
	runUI();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void runUI() {
 | 
			
		||||
	static enum screenStates screenState = PRESSURE;
 | 
			
		||||
 | 
			
		||||
	oled.clearDisplay();
 | 
			
		||||
 | 
			
		||||
	switch (screenState) {
 | 
			
		||||
		case PRESSURE:
 | 
			
		||||
			if (enterButton == HELD) screenState = SETTINGS;
 | 
			
		||||
 | 
			
		||||
			if (upButton == PRESSED) {
 | 
			
		||||
				pressureSetPoint++;
 | 
			
		||||
			} else if (downButton == PRESSED) {
 | 
			
		||||
				pressureSetPoint--;
 | 
			
		||||
			} else if (upButton == HELD) {
 | 
			
		||||
				pressureSetPoint++;
 | 
			
		||||
				delay(75);
 | 
			
		||||
			} else if (downButton == HELD) {
 | 
			
		||||
				pressureSetPoint--;
 | 
			
		||||
				delay(75);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
			oled.setCursor(0,0);
 | 
			
		||||
			oled.setTextSize(3);
 | 
			
		||||
			oled.print(pressureSetPoint);
 | 
			
		||||
 | 
			
		||||
			oled.display();
 | 
			
		||||
 | 
			
		||||
			break;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void pollButtons() {
 | 
			
		||||
	static unsigned long upButtonTime = 0;
 | 
			
		||||
	static unsigned long enterButtonTime = 0;
 | 
			
		||||
	static unsigned long downButtonTime = 0;
 | 
			
		||||
 | 
			
		||||
	processButtonState(UP_BUTTON, upButton, upButtonTime);
 | 
			
		||||
	processButtonState(ENTER_BUTTON, enterButton, enterButtonTime);
 | 
			
		||||
	processButtonState(DOWN_BUTTON, downButton, downButtonTime);
 | 
			
		||||
 | 
			
		||||
	if (DEBUG) {
 | 
			
		||||
		if (upButton == PRESSED) {
 | 
			
		||||
			Serial.println("up button pressed");
 | 
			
		||||
		} else if (upButton == HELD) {
 | 
			
		||||
			Serial.println("up button held");
 | 
			
		||||
		}
 | 
			
		||||
			
 | 
			
		||||
		if (enterButton == PRESSED) {
 | 
			
		||||
			Serial.println("enter button pressed");
 | 
			
		||||
		} else if (enterButton == HELD) {
 | 
			
		||||
			Serial.println("enter button held");
 | 
			
		||||
		}
 | 
			
		||||
			
 | 
			
		||||
		if (downButton == PRESSED) {
 | 
			
		||||
			Serial.println("down button pressed");
 | 
			
		||||
		} else if (downButton == HELD) {
 | 
			
		||||
			Serial.println("down button held");
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void processButtonState(int buttonPin, buttonStates &buttonState, unsigned long &buttonTime) {
 | 
			
		||||
	bool pinState = !digitalRead(buttonPin);
 | 
			
		||||
 | 
			
		||||
	switch(buttonState) {
 | 
			
		||||
		case OPEN:
 | 
			
		||||
			if (pinState) {
 | 
			
		||||
				buttonState = CLOSED;
 | 
			
		||||
				buttonTime = millis();
 | 
			
		||||
			}
 | 
			
		||||
			break;
 | 
			
		||||
		case CLOSED:
 | 
			
		||||
			if (millis() >= buttonTime + BUTTON_HOLD_TIME) {
 | 
			
		||||
				buttonState = HELD;
 | 
			
		||||
			}
 | 
			
		||||
			if (pinState) {
 | 
			
		||||
				;
 | 
			
		||||
			} else {
 | 
			
		||||
				buttonState = CHECK_PRESSED;
 | 
			
		||||
			}
 | 
			
		||||
			break;
 | 
			
		||||
		case CHECK_PRESSED:
 | 
			
		||||
			if (millis() >= buttonTime + BUTTON_PRESS_TIME) {
 | 
			
		||||
				buttonState = PRESSED;
 | 
			
		||||
			} else {
 | 
			
		||||
				buttonState = OPEN;
 | 
			
		||||
			}
 | 
			
		||||
			break;
 | 
			
		||||
		case PRESSED:
 | 
			
		||||
			buttonState = OPEN;
 | 
			
		||||
			break;
 | 
			
		||||
		case HELD:
 | 
			
		||||
			if (!pinState) {
 | 
			
		||||
				buttonState = OPEN;
 | 
			
		||||
			}
 | 
			
		||||
			break;
 | 
			
		||||
		default:
 | 
			
		||||
			break;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										53
									
								
								firmware/pressure/pressure.ino
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								firmware/pressure/pressure.ino
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,53 @@
 | 
			
		||||
/*
 | 
			
		||||
  Analog input, analog output, serial output
 | 
			
		||||
 | 
			
		||||
  Reads an analog input pin, maps the result to a range from 0 to 255 and uses
 | 
			
		||||
  the result to set the pulse width modulation (PWM) of an output pin.
 | 
			
		||||
  Also prints the results to the Serial Monitor.
 | 
			
		||||
 | 
			
		||||
  The circuit:
 | 
			
		||||
  - potentiometer connected to analog pin 0.
 | 
			
		||||
    Center pin of the potentiometer goes to the analog pin.
 | 
			
		||||
    side pins of the potentiometer go to +5V and ground
 | 
			
		||||
  - LED connected from digital pin 9 to ground through 220 ohm resistor
 | 
			
		||||
 | 
			
		||||
  created 29 Dec. 2008
 | 
			
		||||
  modified 9 Apr 2012
 | 
			
		||||
  by Tom Igoe
 | 
			
		||||
 | 
			
		||||
  This example code is in the public domain.
 | 
			
		||||
 | 
			
		||||
  https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogInOutSerial
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
// These constants won't change. They're used to give names to the pins used:
 | 
			
		||||
const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
 | 
			
		||||
const int analogOutPin = 9; // Analog output pin that the LED is attached to
 | 
			
		||||
 | 
			
		||||
int sensorValue = 0;        // value read from the pot
 | 
			
		||||
float outputValue = 0;        // value output to the PWM (analog out)
 | 
			
		||||
 | 
			
		||||
void setup() {
 | 
			
		||||
  // initialize serial communications at 9600 bps:
 | 
			
		||||
  Serial.begin(9600);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loop() {
 | 
			
		||||
  // read the analog in value:
 | 
			
		||||
  sensorValue = analogRead(analogInPin);
 | 
			
		||||
  // map it to the range of the analog out:
 | 
			
		||||
  float adjusted = 0.098 * sensorValue - 16.56 + 3.58;
 | 
			
		||||
 | 
			
		||||
  outputValue = 0.98 * outputValue + 0.02 * adjusted;
 | 
			
		||||
 | 
			
		||||
  // print the results to the Serial Monitor:
 | 
			
		||||
  //Serial.print("sensor = ");
 | 
			
		||||
  //Serial.print(sensorValue);
 | 
			
		||||
  //Serial.print("\t output = ");
 | 
			
		||||
  Serial.print(outputValue);
 | 
			
		||||
  Serial.println(" PSI");
 | 
			
		||||
 | 
			
		||||
  // wait 2 milliseconds before the next loop for the analog-to-digital
 | 
			
		||||
  // converter to settle after the last reading:
 | 
			
		||||
  delay(50);
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user