Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This code collects ACC and EMG signal using Bitalino sensors for an analog input, motivating a person to exercise by screen display.
/*Fitness Motivator
This code collects ACC and EMG signal using Bitalino sensors for an analog input, motivating a person to exercise by screen display.
When the person produces an acceleration above threshold, the green LED will lit up and the screen will show some displays that would encourage them to move faster if their EMG signals indicates that their calves muscle still needs to work harder.
When the person produces an acceleration below threshold, the red LED will lit up and the screen will show "Get up!" to encourage them to get moving.
Date Created: May 5, 2018
By Vy Ho and Matt Brenneman
With the guidances from Dr. Emily Farrar of Messiah College
Tutorial: https://www.instructables.com/id/Fitness-Motivation
*/
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>
// For the breakout, you can use any 2 or 3 pins
// These pins will also work for the 1.8" TFT shield
const int TFT_CS = 10; //default pins
const int TFT_RST = 9; //default pins
const int TFT_DC = 8; //defaults pins
// For 1.44" and 1.8" TFT with ST7735 use
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST); //define the screen as tft
//ACC and EMG variables
const int ACC = A1; //set ACC sensor value, analog input A1
int sensorValue = 0; //initial ACC value of 0
const int EMG = A2; //set EMG sensor value, analog input A2
int EMG_signal = 0; //initial EMG value of 0
//baseline variables
int sensorMin = 1000; //min value for movement
int EMG_threshold = 700; //threshold value for standing
void setup() {
//LED variables
pinMode(2, OUTPUT); //Red LED for pin 2
pinMode(3, OUTPUT); //Green LED for pin 3
//initialize serial comm at 115200 baud (BITalino default)
Serial.begin(115200);
Serial.print("Hello! Testing...Testing..."); //Print testing on the Serial Monitor
// Use this initializer if you're using a 1.8" TFT
tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab
Serial.println("Initialized"); //Print testing on the Serial Monitor
uint16_t time = millis();
tft.fillScreen(ST7735_BLACK); //Set the screen as black background
time = millis() - time;
//Serial.println(time, DEC);
delay(50);
}
void loop() {
//read the signal from the ACC
sensorValue = analogRead(ACC); //Collect ACC data
//Identify ACC value and if the ACC value below the threshold, the red LED will turn on and no EMG data will be collected
if (sensorValue < sensorMin){
digitalWrite(2, HIGH); //Turn Red LED on
digitalWrite(3, LOW); //Turn Green LED off
digitalWrite(EMG, LOW); //No EMG signals are being collected
tft.fillScreen(ST7735_WHITE);
tft.setRotation(3);
tft.setCursor(10, 50);
tft.setTextColor(ST7735_RED);
tft.setTextSize(3);
tft.print("Get up!!");
delay(2000);
}
//If ACC value is above threshold, the green LED will turn on and EMG data will be collected
//The screen will also display "Come on!"
else {
delay(10);
digitalWrite(2, LOW); //Turn Red LED off
digitalWrite(3, HIGH); //Turn Green LED on
digitalWrite(EMG, HIGH); //Collecting EMG signals
EMG_signal = analogRead(EMG);
tft.fillScreen(ST7735_WHITE);
tft.setRotation(3);
tft.setCursor(10, 50);
tft.setTextColor(ST7735_BLACK);
tft.setTextSize(3);
tft.print("Come on!");
delay(2000);
//identify EMG value. If EMG signal is above threshold, the screen will display "Great job!"
if (EMG_signal > EMG_threshold){
tft.fillScreen(ST7735_WHITE);
tft.setRotation(3);
tft.setCursor(10, 50);
tft.setTextColor(ST7735_BLUE);
tft.setTextSize(2.5);
tft.print("Great job!");
delay(2000);
}
//If the EMG signal is below threshold, the screen will display "Get going!"
else {
tft.fillScreen(ST7735_WHITE);
tft.setRotation(3);
tft.setCursor(10, 50);
tft.setTextColor(ST7735_GREEN);
tft.setTextSize(2.5);
tft.print("Get going!");
delay(2000);
}
}
//print readings of ACC values and EMG values via USB to serial monitor
Serial.print(sensorValue);
Serial.print(",");
Serial.println(EMG_signal);
//wait 5 milliseconds for stability
delay(5);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment