// Esp32 S3 and two I2C buses with Adafruit SSD1306 library (Two OLED 128x64 displays)
// Forum: https://forum.arduino.cc/t/esp32-s3-and-two-i2c-buses-with-adafruit-ssd1306-library-two-oled-128x64-displays/1290094
// Sketch by user: marko-2347
// This Wokwi project: https://wokwi.com/projects/405730495697247233
//CARA PENGGUNAAN :
//1. Tombol 1 >>> Jumlah pembelian Rail A = 0
//2. Tombol 2 >>> Jumlah pembelian Rail A = 1
//3. Tombol 3 >>> Jumlah pembelian Rail A = 2
//4. Tombol A >>> Jumlah pembelian Rail A = 3
//5. Tombol 4 >>> Jumlah pembelian Rail B = 0
//6. Tombol 5 >>> Jumlah pembelian Rail B = 1
//7. Tombol 6 >>> Jumlah pembelian Rail B = 2
//8. Tombol B >>> Jumlah pembelian Rail B = 3
//9. Tombol * >>> Submit order ke API Server
//10. Tombol # >>> Konfirmasi pembayaran (Jika status Pembayaran "Berhasil" maka masing2 Servo akan bergerak mengeluarkan produk sesuai jumlah yang di order)
// OLED
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Keypad.h>
#include <Stepper.h>
//Define pins OLED
#define I2C_A_SDA 1 // GPIO1
#define I2C_A_SCL 2 // GPIO2
#define I2C_B_SDA 42 // GPIO42
#define I2C_B_SCL 41 // GPIO41
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
const int stepsPerRevolution2 = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins
Stepper myStepper(stepsPerRevolution, 19, 20, 21, 47);
Stepper myStepper2(stepsPerRevolution2, 35, 36, 37, 38);
// OLED parameters
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C // Change if required
#define ROTATION 0 // Rotates text on OLED 1=90 degrees, 2=180 degrees
// Define display object
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_SSD1306 display2(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire1, OLED_RESET);
// Inisialisasi keypad
const byte ROWS = 4; //jumlah baris pada keypad
const byte COLS = 4; //jumlah kolom pada keypad
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {18, 17, 16, 15}; //sesuaikan pinnya sesuai dengan koneksi Anda
byte colPins[COLS] = {7, 6, 5, 4}; //sesuaikan pinnya sesuai dengan koneksi Anda
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int harga = 5000;
int harga2 = 10000;
int jumlah = 0;
int jumlah2 = 0;
int ammount = 0;
int ammount2 = 0;
int total_ammount = 0;
int R1 = 0;
int R2 = 0;
void setup() {
Serial.begin(115200);
while (!Serial)
;
Wire.begin(I2C_A_SDA, I2C_A_SCL);
Wire1.begin(I2C_B_SDA, I2C_B_SCL);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("Display1 SSD1306 allocation failed"));
for (;;)
; // Don't proceed, loop forever
}
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if (!display2.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("Display2 SSD1306 allocation failed"));
for (;;)
; // Don't proceed, loop forever
}
// Show splash screen
display.display();
display2.display();
delay(2000); // Pause for 2 seconds
// Display settings
display.clearDisplay();
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(WHITE); // Draw white text
display.setRotation(ROTATION); // Set screen rotation
display.setCursor(0,0); // Start at top-left corner
display.print("Rail A x 0");
display.setCursor(0,24); // Start at top-left corner
display.print("Rp ");
display.print(ammount);
display.display();
// Display settings
display2.clearDisplay();
display2.setTextSize(2); // Normal 1:1 pixel scale
display2.setTextColor(WHITE); // Draw white text
display2.setRotation(ROTATION); // Set screen rotation
display2.setCursor(0,0); // Start at top-left corner
display2.print("Rail B x 0");
display2.print("Rp ");
display2.print(ammount2);
display2.display();
// set the speed at 60 rpm:
myStepper.setSpeed(60);
myStepper2.setSpeed(60);
}
void loop() {
char key = keypad.getKey();
if (key == '1') {
jumlah = 0;
ammount = harga * jumlah;
total_ammount = ammount + ammount2;
// Display settings
display.clearDisplay();
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(WHITE); // Draw white text
display.setRotation(ROTATION); // Set screen rotation
display.setCursor(0,0); // Start at top-left corner
display.print("Rail A x ");
display.print(jumlah);
display.setCursor(0,24); // Start at top-left corner
display.print("Rp ");
display.print(ammount);
display.display();
}
if (key == '2') {
jumlah = 1;
ammount = harga * jumlah;
total_ammount = ammount + ammount2;
// Display settings
display.clearDisplay();
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(WHITE); // Draw white text
display.setRotation(ROTATION); // Set screen rotation
display.setCursor(0,0); // Start at top-left corner
display.print("Rail A x ");
display.print(jumlah);
display.setCursor(0,24); // Start at top-left corner
display.print("Rp ");
display.print(ammount);
display.display();
}
if (key == '3') {
jumlah = 2;
ammount = harga * jumlah;
total_ammount = ammount + ammount2;
// Display settings
display.clearDisplay();
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(WHITE); // Draw white text
display.setRotation(ROTATION); // Set screen rotation
display.setCursor(0,0); // Start at top-left corner
display.print("Rail A x ");
display.print(jumlah);
display.setCursor(0,24); // Start at top-left corner
display.print("Rp ");
display.print(ammount);
display.display();
}
if (key == 'A') {
jumlah = 3;
ammount = harga * jumlah;
total_ammount = ammount + ammount2;
// Display settings
display.clearDisplay();
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(WHITE); // Draw white text
display.setRotation(ROTATION); // Set screen rotation
display.setCursor(0,0); // Start at top-left corner
display.print("Rail A x ");
display.print(jumlah);
display.setCursor(0,24); // Start at top-left corner
display.print("Rp ");
display.print(ammount);
display.display();
}
if (key == '4') {
jumlah2 = 0;
ammount2 = harga2 * jumlah2;
total_ammount = ammount + ammount2;
// Display settings
display2.clearDisplay();
display2.setTextSize(2); // Normal 1:1 pixel scale
display2.setTextColor(WHITE); // Draw white text
display2.setRotation(ROTATION); // Set screen rotation
display2.setCursor(0,0); // Start at top-left corner
display2.print("Rail B x ");
display2.print(jumlah2);
display2.setCursor(0,24); // Start at top-left corner
display2.print("Rp ");
display2.print(ammount2);
display2.display();
}
if (key == '5') {
jumlah2 = 1;
ammount2 = harga2 * jumlah2;
total_ammount = ammount + ammount2;
// Display settings
display2.clearDisplay();
display2.setTextSize(2); // Normal 1:1 pixel scale
display2.setTextColor(WHITE); // Draw white text
display2.setRotation(ROTATION); // Set screen rotation
display2.setCursor(0,0); // Start at top-left corner
display2.print("Rail B x ");
display2.print(jumlah2);
display2.setCursor(0,24); // Start at top-left corner
display2.print("Rp ");
display2.print(ammount2);
display2.display();
}
if (key == '6') {
jumlah2 = 2;
ammount2 = harga2 * jumlah2;
total_ammount = ammount + ammount2;
// Display settings
display2.clearDisplay();
display2.setTextSize(2); // Normal 1:1 pixel scale
display2.setTextColor(WHITE); // Draw white text
display2.setRotation(ROTATION); // Set screen rotation
display2.setCursor(0,0); // Start at top-left corner
display2.print("Rail B x ");
display2.print(jumlah2);
display2.setCursor(0,24); // Start at top-left corner
display2.print("Rp ");
display2.print(ammount2);
display2.display();
}
if (key == 'B') {
jumlah2 = 3;
ammount2 = harga2 * jumlah2;
total_ammount = ammount + ammount2;
// Display settings
display2.clearDisplay();
display2.setTextSize(2); // Normal 1:1 pixel scale
display2.setTextColor(WHITE); // Draw white text
display2.setRotation(ROTATION); // Set screen rotation
display2.setCursor(0,0); // Start at top-left corner
display2.print("Rail B x ");
display2.print(jumlah2);
display2.setCursor(0,24); // Start at top-left corner
display2.print("Rp ");
display2.print(ammount2);
display2.display();
}
if (key == '*') {
// Display settings
display.clearDisplay();
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(WHITE); // Draw white text
display.setRotation(ROTATION); // Set screen rotation
display.setCursor(0,0); // Start at top-left corner
display.print("BAYAR !!!");
display.setCursor(0,24); // Start at top-left corner
display.print("Rp ");
display.print(total_ammount);
display.display();
// Display settings
display2.clearDisplay();
display2.setTextSize(2); // Normal 1:1 pixel scale
display2.setTextColor(WHITE); // Draw white text
display2.setRotation(ROTATION); // Set screen rotation
display2.setCursor(0,0); // Start at top-left corner
display2.print("BAYAR !!!");
display2.setCursor(0,24); // Start at top-left corner
display2.print("Rp ");
display2.print(total_ammount);
display2.display();
}
if (key == '#') {
for (R1 = 0; R1 < jumlah; R1++) {
// step one revolution in one direction:
Serial.println("motor1");
myStepper.step(stepsPerRevolution);
delay(500);
// Display settings
display.clearDisplay();
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(WHITE); // Draw white text
display.setRotation(ROTATION); // Set screen rotation
display.setCursor(0,0); // Start at top-left corner
display.print("SABAR ...");
display.setCursor(0,24); // Start at top-left corner
display.print(R1);
display.display();
}
for (R2 = 0; R2 < jumlah2; R2++) {
Serial.println("motor2");
myStepper2.step(stepsPerRevolution2);
delay(500);
// Display settings
display2.clearDisplay();
display2.setTextSize(2); // Normal 1:1 pixel scale
display2.setTextColor(WHITE); // Draw white text
display2.setRotation(ROTATION); // Set screen rotation
display2.setCursor(0,0); // Start at top-left corner
display2.print("Sabar ...");
display2.setCursor(0,24); // Start at top-left corner
display2.print(R2);
display2.display();
}
}
}Loading
esp32-s3-devkitc-1
esp32-s3-devkitc-1