Skip to content
Snippets Groups Projects
Commit 88fb0af1 authored by Sebastian Hyland's avatar Sebastian Hyland
Browse files

feat(import): imported all firmware and UI files

parent c05076c6
No related branches found
No related tags found
No related merge requests found
void setup() {
pinMode(7, OUTPUT);
pinMode(11, OUTPUT);
Serial.begin(9600);
}
void loop() {
Serial.print("LEFT: ");
Serial.print(digitalRead(7));
Serial.print("\tRIGHT: ");
Serial.println(digitalRead(11));
}
const int dirPin = 3;
const int stepPin = 2;
const int stepsPerRevolution = 1600;
int initSpeed = 300;
int curDir = HIGH;
int mixingSpeed = 500;
int numRotations = 0;
float mixingDistance = 0.0;
void setup() {
Serial.begin(9600);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
delay(2000);
Serial.println(" @");
Serial.println(" @@ @");
Serial.println(" @@ @");
Serial.println(" @@ @@ @@");
Serial.println(" @@ @@@ @@@");
Serial.println(" @ @@@ @@@");
Serial.println(" @@@@ @@@@@ @@@");
Serial.println(" @@@@@@ @@@ @@@@@");
Serial.println(" @@@ @@ @@@ @@@@@ @@");
Serial.println(" @ @@ @@ @@@@@@@@");
Serial.println(" @@ @@ @@@@@@@@@@");
Serial.println(" @@ @@@@ @@ @@@");
Serial.println(" @@@ @@ @@ @@");
Serial.println(" @@ @@@ @@");
Serial.println(" @@@@@@@ @");
Serial.println(" @@@@@@@@@@");
Serial.println(" @@ @@");
Serial.println(" @@ @@");
Serial.println(" @@@");
Serial.println(" @@ @@");
Serial.println(" @@ @@");
Serial.println("\nWelcome to the UBC-iGEM 2024 Microfluidic Pump System.");
Serial.println("At any point during operation, input \"s\" to stop the pump system.\n");
Serial.println("----------------------------------------------------------------------\n");
Serial.println("Ready to align motor and clear syringes. Press 0 when motor path is clear.");
while (Serial.read() != '0') {}
Serial.println("Press 0 to stop when the pump contacts the end of its chamber.");
digitalWrite(dirPin, HIGH);
while (Serial.read() != '0')
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(initSpeed);
digitalWrite(stepPin, LOW);
delayMicroseconds(initSpeed);
}
Serial.println("Ensure motor path and output syringe are clear. Press 0 to begin initial system aeration.");
while (Serial.read() != '0') {}
Serial.println("Starting initial air suction.");
digitalWrite(dirPin, LOW);
for (int x = 0; x < stepsPerRevolution * 2; x++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(initSpeed);
digitalWrite(stepPin, LOW);
delayMicroseconds(initSpeed);
}
Serial.println("Ready to receive fluid one. Press 1 to start.");
while (Serial.read() != '1') {}
Serial.println("Press 1 to stop when all of fluid 1 has been suctioned.");
while (Serial.read() != '1') {
digitalWrite(stepPin, HIGH);
delayMicroseconds(initSpeed / 1.5);
digitalWrite(stepPin, LOW);
delayMicroseconds(initSpeed / 1.5);
}
// Serial.println("Ready to receive fluid two. Press 2 to start.");
// while (Serial.read() != '2') {}
// Serial.println("Press 2 to stop when all of fluid 2 has been suctioned.");
// while (Serial.read() != '2') {
// digitalWrite(stepPin, HIGH);
// delayMicroseconds(initSpeed / 2.5);
// digitalWrite(stepPin, LOW);
// delayMicroseconds(initSpeed / 2.5);
// }
Serial.println("Ready to clear output pipe. Press 0 to start.");
while (Serial.read() != '0') {}
Serial.println("Press 0 to stop when output line has been cleared.");
while (Serial.read() != '0') {
digitalWrite(stepPin, HIGH);
delayMicroseconds(initSpeed * 3);
digitalWrite(stepPin, LOW);
delayMicroseconds(initSpeed * 3);
mixingDistance += 0.25;
}
Serial.println("Ready to calibrate mixing. Press 0 to start.");
while (Serial.read() != '0') {}
Serial.println("Press 0 to stop when full mixing depth has been reached.");
while (Serial.read() != '0') {
digitalWrite(stepPin, HIGH);
delayMicroseconds(initSpeed * 5);
digitalWrite(stepPin, LOW);
delayMicroseconds(initSpeed * 5);
mixingDistance++;
}
numRotations = int(mixingDistance);
Serial.println(mixingDistance);
Serial.println("Calibration complete. Now running standard mixing cycle. Press \"o\" when ready to output fluid.");
}
void loop() {
digitalWrite(dirPin, curDir);
for (int x = 0; x < numRotations; x++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(mixingSpeed);
digitalWrite(stepPin, LOW);
delayMicroseconds(mixingSpeed);
if (Serial.read() == 'o') {
Serial.println("Outputting liquid now. Press \"s\" when all liquid has been output.");
while (Serial.read() != 's') {
digitalWrite(dirPin, HIGH);
digitalWrite(stepPin, HIGH);
delayMicroseconds(initSpeed);
digitalWrite(stepPin, LOW);
delayMicroseconds(initSpeed);
mixingDistance++;
}
Serial.println("Thank you for using the UBC-iGEM microfluidic platform. The microfluidic protocol has concluded.");
while (true) {} // Stops the program.
}
}
curDir = !curDir;
}
const int dirPin = 3;
const int stepPin = 2;
const int stepsPerRevolution = 1600;
int curStep = 0;
int curDir = HIGH;
int curSpeed = 1000;
int numRotations = 0;
void setup()
{
// Declare pins as Outputs
Serial.begin(9600); // open the serial port at 9600 bps:
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
}
void loop()
{
// Set motor direction clockwise
digitalWrite(dirPin, curDir);
if (curDir == HIGH) {
curSpeed = 1000;
}
else {
curSpeed = 5000;
}
// Spin motor slowly
for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(curSpeed);
digitalWrite(stepPin, LOW);
delayMicroseconds(curSpeed);
}
curStep += 1;
Serial.println(curStep);
if(curStep == 7) {
curDir = !curDir;
curStep = 0;
}
// delay(1000); // Wait a second
}
#include <DHT.h>
const int DHTPIN = 12;
DHT dht(DHTPIN, DHT11);
const int MOTOR_PIN_1 = 9;
const int MOTOR_PIN_2 = 10;
const int SPEED_PIN = 8;
const int LED_0_PIN = 3;
const int LED_1_PIN = 4;
const int LED_2_PIN = 2;
const int LED_ON_PIN = 5;
const int LED_OFF_PIN = 6;
const int STATE_BUTTON_PIN = 7;
const int OO_BUTTON_PIN = 11;
bool mixingLiquid = true; // whether pushing air or liquid during mixing
unsigned long curTime = 0;
unsigned long lastMix = 0;
unsigned long lastStateSwitch = 0;
unsigned long lastOOSwitch = 0;
bool OO_state = false;
int progIndex = 0;
unsigned long lastFlash = 0;
bool flashState = true;
int STATE_buttonReading = LOW;
int STATE_buttonPrevReading = LOW;
int OO_buttonReading = LOW;
int OO_buttonPrevReading = LOW;
void setup() {
Serial.begin(9600);
dht.begin();
pinMode(MOTOR_PIN_1, OUTPUT);
pinMode(MOTOR_PIN_2, OUTPUT);
pinMode(SPEED_PIN, OUTPUT);
pinMode(LED_0_PIN, OUTPUT);
pinMode(LED_1_PIN, OUTPUT);
pinMode(LED_2_PIN, OUTPUT);
pinMode(LED_OFF_PIN, OUTPUT);
pinMode(LED_ON_PIN, OUTPUT);
pinMode(STATE_BUTTON_PIN, INPUT);
pinMode(OO_BUTTON_PIN, INPUT);
digitalWrite(LED_0_PIN, HIGH);
digitalWrite(LED_1_PIN, LOW);
digitalWrite(LED_2_PIN, LOW);
digitalWrite(LED_OFF_PIN, HIGH);
digitalWrite(LED_ON_PIN, LOW);
}
void dhtRead() {
float temp = dht.readTemperature();
float humidity = dht.readHumidity();
if (isnan(temp) || isnan(humidity)) {
Serial.println("Failed to read from DHT sensor!");
}
else {
Serial.print("Temperature: ");
Serial.print(temp);
Serial.print("°C\tHumidity: ");
Serial.print(humidity);
Serial.println("%");
}
}
void fluidIn(int flow) {
analogWrite(SPEED_PIN, flow);
digitalWrite(MOTOR_PIN_1, LOW);
digitalWrite(MOTOR_PIN_2, HIGH);
}
void fluidOut(int flow) {
analogWrite(SPEED_PIN, flow);
digitalWrite(MOTOR_PIN_1, HIGH);
digitalWrite(MOTOR_PIN_2, LOW);
}
void mixer(int flow, int time) {
if (mixingLiquid == true && curTime > (lastMix + time)) {
fluidIn(flow);
lastMix = curTime;
mixingLiquid = false;
}
else if (mixingLiquid == false && curTime > (lastMix + (time * 2))) {
fluidOut(flow);
lastMix = curTime;
mixingLiquid = true;
}
}
void off() {
digitalWrite(MOTOR_PIN_1, LOW);
digitalWrite(MOTOR_PIN_2, LOW);
}
void stateLEDOn() {
switch (progIndex) {
case 0:
digitalWrite(LED_0_PIN, HIGH);
digitalWrite(LED_1_PIN, LOW);
digitalWrite(LED_2_PIN, LOW);
Serial.println("LIGHT ONE ON");
break;
case 1:
digitalWrite(LED_0_PIN, LOW);
digitalWrite(LED_1_PIN, HIGH);
digitalWrite(LED_2_PIN, LOW);
Serial.println("LIGHT TWO ON");
break;
case 2:
digitalWrite(LED_0_PIN, LOW);
digitalWrite(LED_1_PIN, LOW);
digitalWrite(LED_2_PIN, HIGH);
Serial.println("LIGHT THREE ON");
break;
}
}
void stateLEDControl() {
// if (OO_state) {
// stateLEDOn(stateLEDIndex);
// }
// else {
// if (curTime > lastFlash + 300) {
// flashState = !flashState;
// lastFlash = curTime;
// }
// if (flashState) {
// stateLEDOn(stateLEDIndex);
// }
// else {
// digitalWrite(LED_0_PIN, LOW);
// digitalWrite(LED_1_PIN, LOW);
// digitalWrite(LED_2_PIN, LOW);
// }
// }
stateLEDOn();
}
void readStateButton() {
STATE_buttonReading = digitalRead(STATE_BUTTON_PIN);
if (STATE_buttonReading == HIGH &&
STATE_buttonPrevReading == LOW &&
curTime > lastStateSwitch + 50 &&
OO_state == false) {
STATE_buttonPrevReading = HIGH;
lastStateSwitch = curTime;
}
if (STATE_buttonReading == LOW &&
STATE_buttonPrevReading == HIGH &&
curTime > lastStateSwitch + 50 &&
OO_state == false) {
STATE_buttonPrevReading = LOW;
lastStateSwitch = curTime;
// progIndex bounds from 0 to 2
// This moves progIndex to its next value
// 0 -> 1, 1 -> 2, 2 -> 0
progIndex = (progIndex + 1) % 3;
stateLEDControl();
}
}
void runProg(int flow, int time) {
if (OO_state == true) {
switch (progIndex) {
case 0:
mixer(flow, time);
Serial.println("Running mixer");
break;
case 1:
fluidIn(flow);
Serial.println("Running fluidIN");
break;
case 2:
fluidOut(flow);
Serial.println("Running fluidOUT");
break;
}
}
else {
off();
}
}
void readOOButton() {
OO_buttonReading = digitalRead(OO_BUTTON_PIN);
if (OO_buttonReading == HIGH && OO_buttonPrevReading == LOW && curTime > lastOOSwitch + 50) {
OO_buttonPrevReading = HIGH;
lastOOSwitch = curTime;
}
if (OO_buttonReading == LOW && OO_buttonPrevReading == HIGH && curTime > lastOOSwitch + 50) {
OO_buttonPrevReading = LOW;
lastOOSwitch = curTime;
if (OO_state == false) {
OO_state = true;
mixingLiquid = true;
digitalWrite(LED_OFF_PIN, LOW);
digitalWrite(LED_ON_PIN, HIGH);
}
else {
OO_state = false;
digitalWrite(LED_OFF_PIN, HIGH);
digitalWrite(LED_ON_PIN, LOW);
}
}
}
void loop() {
curTime = millis();
readOOButton();
dhtRead();
readStateButton();
runProg(220, 2000);
}
#include <DHT.h>
#include <Keypad.h>
const int DHTPIN = 13;
DHT dht(DHTPIN, DHT11);
const int MOTOR_PIN_1 = 3;
const int MOTOR_PIN_2 = 4;
const int SPEED_PIN = 2;
bool mixingLiquid = true; // whether pushing air or liquid during mixing
unsigned long curTime = 0;
unsigned long lastMix = 0;
int progIndex = 1;
char hexaKeys[2][2] = {
{'1', '2'},
{'4', '5'}
};
byte rowPins[2] = {8, 7};
byte colPins[2] = {6, 5};
Keypad controlPad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, 2, 2);
void setup() {
Serial.begin(9600);
dht.begin();
pinMode(MOTOR_PIN_1, OUTPUT);
pinMode(MOTOR_PIN_2, OUTPUT);
pinMode(SPEED_PIN, OUTPUT);
}
void dhtRead() {
float temp = dht.readTemperature();
float humidity = dht.readHumidity();
if (isnan(temp) || isnan(humidity)) {
Serial.println("Failed to read from DHT sensor!");
}
else {
Serial.print("Temperature: ");
Serial.print(temp);
Serial.print("°C\tHumidity: ");
Serial.print(humidity);
Serial.println("%");
}
}
void fluidIn(int flow) {
analogWrite(SPEED_PIN, flow);
digitalWrite(MOTOR_PIN_1, HIGH);
digitalWrite(MOTOR_PIN_2, LOW);
}
void fluidOut(int flow) {
analogWrite(SPEED_PIN, flow);
digitalWrite(MOTOR_PIN_1, LOW);
digitalWrite(MOTOR_PIN_2, HIGH);
}
void mixer(int flow, int time) {
if (mixingLiquid == true && curTime > (lastMix + time)) {
fluidIn(flow);
lastMix = curTime;
mixingLiquid = false;
}
else if (mixingLiquid == false && curTime > (lastMix + (time * 2))) {
fluidOut(flow);
lastMix = curTime;
mixingLiquid = true;
}
}
void readOD(int flow) {
fluidIn(flow);
delay(2250);
fluidOut(flow);
delay(3500);
}
void off() {
digitalWrite(MOTOR_PIN_1, LOW);
digitalWrite(MOTOR_PIN_2, LOW);
}
void runProg(int flow, int time) {
switch (progIndex) {
case 1:
off();
break;
case 2:
mixer(flow, time);
break;
case 4:
fluidIn(flow);
break;
case 5:
fluidOut(flow);
break;
}
}
void readNumpad() {
char readingKey = controlPad.getKey();
progIndex = (readingKey) ? readingKey - '0' : progIndex;
if (readingKey) {
Serial.print("Key: ");
Serial.print(readingKey);
Serial.print("/tProg: ");
Serial.println(progIndex);
}
}
void loop() {
curTime = millis();
// dhtRead();
readNumpad();
runProg(220, 7000);
// fluidIn(200);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment