/*
Project Name: GUI stage_2 1.1.0 arduino IDE control interface
Description:
Arduino waveform output to control motor motion
using arduino IDE Serial print plotter to display motor output value.
Copyright (CC) 2024, Ryan Lin.
Date: 2024/7/25
*/
#include <Button.h>
// ============================================================================================The value can be changed
Button button1(10);
#define motor_1 = 5;
#define SAMPLE_NUM 5 // number of waveform point
int waveTable[SAMPLE_NUM] = {0, 50, 20, 30, 20}; //power of waveform point.
int holding_time[SAMPLE_NUM] = {100, 500, 100, 500, 100}; //holding max level delay time.
// =============================================================================================
int num = 0;
int mode_num = 5;
int button_num = 0;
unsigned long previousMillis = 0;
unsigned long currentMillis = 0;
void Button_pressed(){
if(button1.pressed()){
button_num++;
if(button_num >= mode_num){button_num = 0;}
Serial.println(button_num);
}
}
void waveOutput() {
currentMillis = millis();
if (currentMillis - previousMillis > holding_time[num]) {
previousMillis = currentMillis;
num++;
if (num >= SAMPLE_NUM) {
num = 0;
}
}
}
void setup() {
button1.begin();
Serial.begin(9600);
}
void loop() {
waveOutput();
// analogWrite(motor_1, map(waveTable[num], 0, 100, 0, 255));
Button_pressed();
Serial.print(waveTable[num]);
Serial.print(",");
Serial.print(num);
Serial.print(",");
Serial.print(button_num);
Serial.print(",");
Serial.println((waveTable[num]/mode_num)*(button_num+1));
}