#include <TM1637Display.h>
#define CLK1 10
#define DIO1 11
TM1637Display display1(CLK1, DIO1);
char ArtNetHead[8] = "Art-Net";
const int art_net_header_size = 17;
const int number_of_channels = 512; // 512 for 512 channels, MAX=512c
byte buffer_dmx[number_of_channels]; // buffer used for DMX data
byte ArtDmxBuffer[(art_net_header_size + number_of_channels) + 10 + 1];
// int val;
const int number_of_channels1 = 10;
int last_values[10] = {0}; // Store the last values of faders
int A_button1 = 6;
int A_button2 = 5;
int A_button3 = 2;
int S1_switch1 = 9;
int S1_switch2 = 8;
int S1_switch3 = 7;
int S1_switch00 = 0; // memory save
int stored_values_00[10] = {0}; // Store the values when S1_switch00 is long-pressed
int Last = 0;
int n = LOW;
int s = LOW;
int d = LOW;
int f = LOW;
int g = LOW;
int h = LOW;
int j = LOW;
void setup() {
pinMode(A_button1, INPUT);
pinMode(A_button2, INPUT_PULLUP);
pinMode(A_button3, INPUT_PULLUP);
pinMode(S1_switch1, INPUT_PULLUP);
Serial.begin(9600);
for (int i = 2; i <= 13; i++) {
pinMode(i, INPUT_PULLUP);
digitalWrite(i, HIGH);
}
display1.setBrightness(1);
display1.clear();
}
void loop() {
check_arduino_inputs();
sw_A();
button_A();
memory();
}
void sw_A() {
digitalRead(S1_switch1);
delay(40);
digitalRead(S1_switch1);
j = digitalRead(S1_switch1);
if (j == LOW) {
Serial.print("sw1_ON");
Serial.print("/");
}
}
void button_A() {
digitalRead(A_button1);
delay(5);
digitalRead(A_button1);
s = digitalRead(A_button1);
if (s == LOW) {
buffer_dmx[13] = 255; //オンで255
display1.showNumberDec(3333, 0, 4);
Serial.print("push_A1");
Serial.print("/");
} else {
buffer_dmx[13] = 0; //離すとゼロ
}
digitalRead(A_button2);
delay(5);
digitalRead(A_button2);
d = digitalRead(A_button2);
if (d == LOW) {
buffer_dmx[12] = 255; //オンで255
display1.showNumberDec(2222, 0, 4);
Serial.print("push_A2");
Serial.print("/");
} else {
buffer_dmx[12] = 0; //離すとゼロ
}
digitalRead(A_button3);
delay(5);
digitalRead(A_button3);
f = digitalRead(A_button3);
if (f == LOW) {
buffer_dmx[11] = 255; //オンで255
display1.showNumberDec(1111, 0, 4);
Serial.print("push_A3");
Serial.print("/");
} else {
buffer_dmx[11] = 0; //離すとゼロ
}
}
void check_arduino_inputs() {
int current_values[10] = {0}; // Store the current values of faders
for (int i = 0; i < number_of_channels1; i++) {
buffer_dmx[i] = byte((analogRead(i)) / 4); // Map 0-255 to 0-15
current_values[i] = buffer_dmx[i];
if (current_values[i] != last_values[i]) {
display1.showNumberDec(current_values[i], 0, 4); // Display the value
last_values[i] = current_values[i]; // Update the last value
}
}
}
void memory() {
digitalRead(S1_switch00);
delay(40);
digitalRead(S1_switch00);
g = digitalRead(S1_switch00);
if (g == LOW) {
// S1_switch00 is long-pressed, store the current values
for (int i = 0; i < number_of_channels1; i++) {
stored_values_00[i] = buffer_dmx[i];
}
Serial.println("Stored values for S1_switch00:");
for (int i = 0; i < number_of_channels1; i++) {
Serial.print(stored_values_00[i]);
Serial.print(" ");
}
Serial.println();
delay(1000); // Add a delay to avoid multiple readings during long-press
}
// Short-press logic for loading stored values
digitalRead(S1_switch00);
delay(5);
digitalRead(S1_switch00);
g = digitalRead(S1_switch00);
if (g == LOW) {
// S1_switch00 is short-pressed, load the stored values
for (int i = 0; i < number_of_channels1; i++) {
buffer_dmx[i] = stored_values_00[i];
}
Serial.println("Loaded values for S1_switch00:");
for (int i = 0; i < number_of_channels1; i++) {
Serial.print(buffer_dmx[i]);
Serial.print(" ");
}
Serial.println();
// Display the loaded values on the TM1637 display
for (int i = 0; i < number_of_channels1; i++) {
display1.showNumberDec(buffer_dmx[i], 0, 4);
delay(1000);
}
}
}