Ik ben wat aan het spelen met een Arduino en een 128x32 Oled scherm.
Wat ik wil maken is een scherm waarbij 10 rechthoekjes staan.
En elke rechthoekje moet de status van een ingangspin weergeven.
Dus leeg vakje, is ingang laag, gevuld vakje, is ingang hoog.
Nu heb ik heel basic iets geschreven, echter is de refresh time zeer langzaam. Enig idee hoe ik dit kan versnellen zodat alles teglijk gewijzigd wordt?
In onderstaande video is dit duidelijk te zien:
https://youtu.be/XPRiIRFke18
c code:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 display(-1);
// constants won't change. They're used here to set pin numbers:
const int Loop_1Pin = 2; // Loop 1
const int Loop_2Pin = 3; // Loop 2
const int Loop_3Pin = 4; // Loop 3
const int Loop_4Pin = 5; // Loop 4
const int Loop_5Pin = 6; // Loop 5
const int Loop_6Pin = 7; // Loop 6
const int Loop_7Pin = 8; // Loop 7
const int Loop_8Pin = 9; // Loop 8
const int Amp_1Pin = 10; // Amp 1
const int Amp_2Pin = 11; // Amp 2
// variables will change:
int Loop_1State = 0;
int Loop_2State = 0;
int Loop_3State = 0;
int Loop_4State = 0;
int Loop_5State = 0;
int Loop_6State = 0;
int Loop_7State = 0;
int Loop_8State = 0;
int Amp_1State = 0;
int Amp_2State = 0;
void setup()
{
// initialize with the I2C addr 0x3C
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
// Clear the buffer.
display.clearDisplay();
// Display Text
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("Loop");
display.setCursor(108,0);
display.println("Amp");
display.setCursor(2,8);
display.println("1");
display.setCursor(14,8);
display.println("2");
display.setCursor(26,8);
display.println("3");
display.setCursor(38,8);
display.println("4");
display.setCursor(50,8);
display.println("5");
display.setCursor(62,8);
display.println("6");
display.setCursor(74,8);
display.println("7");
display.setCursor(86,8);
display.println("8");
display.setCursor(110,8);
display.println("1");
display.setCursor(122,8);
display.println("2");
}
void loop() {
// read the state of the pushbutton value:
Loop_1State = digitalRead(Loop_1Pin);
Loop_2State = digitalRead(Loop_2Pin);
Loop_3State = digitalRead(Loop_3Pin);
Loop_4State = digitalRead(Loop_4Pin);
Loop_5State = digitalRead(Loop_5Pin);
Loop_6State = digitalRead(Loop_6Pin);
Loop_7State = digitalRead(Loop_7Pin);
Loop_8State = digitalRead(Loop_8Pin);
Amp_1State = digitalRead(Amp_1Pin);
Amp_2State = digitalRead(Amp_2Pin);
//Loop 1
if (Loop_1State == HIGH) {
// turn Loop 1 on:
display.fillRect(0, 16, 8, 16, WHITE);
display.display();
} else {
display.fillRect(0, 16, 8, 16, BLACK);
display.drawRect(0, 16, 8, 16, WHITE);
display.display();
}
//Loop 2
if (Loop_1State == HIGH) {
// turn Loop 2 on:
display.fillRect(12, 16, 8, 16, WHITE);
display.display();
} else {
display.fillRect(12, 16, 8, 16, BLACK);
display.drawRect(12, 16, 8, 16, WHITE);
display.display();
}
//Loop 3
if (Loop_3State == HIGH) {
// turn Loop 3 on:
display.fillRect(24, 16, 8, 16, WHITE);
display.display();
} else {
display.fillRect(24, 16, 8, 16, BLACK);
display.drawRect(24, 16, 8, 16, WHITE);
display.display();
}
//Loop 4
if (Loop_4State == HIGH) {
// turn Loop 4 on:
display.fillRect(36, 16, 8, 16, WHITE);
display.display();
} else {
display.fillRect(36, 16, 8, 16, BLACK);
display.drawRect(36, 16, 8, 16, WHITE);
display.display();
}
//Loop 5
if (Loop_5State == HIGH) {
// turn Loop 5 on:
display.fillRect(48, 16, 8, 16, WHITE);
display.display();
} else {
display.fillRect(48, 16, 8, 16, BLACK);
display.drawRect(48, 16, 8, 16, WHITE);
display.display();
}
//Loop 6
if (Loop_6State == HIGH) {
// turn Loop 6 on:
display.fillRect(60, 16, 8, 16, WHITE);
display.display();
} else {
display.fillRect(60, 16, 8, 16, BLACK);
display.drawRect(60, 16, 8, 16, WHITE);
display.display();
}
//Loop 7
if (Loop_7State == HIGH) {
// turn Loop 7 on:
display.fillRect(72, 16, 8, 16, WHITE);
display.display();
} else {
display.fillRect(72, 16, 8, 16, BLACK);
display.drawRect(72, 16, 8, 16, WHITE);
display.display();
}
//Loop 8
if (Loop_8State == HIGH) {
// turn Loop 8 on:
display.fillRect(84, 16, 8, 16, WHITE);
display.display();
} else {
display.fillRect(84, 16, 8, 16, BLACK);
display.drawRect(84, 16, 8, 16, WHITE);
display.display();
}
//Amp 1
if (Amp_1State == HIGH) {
// turn Amp 1 on:
display.fillRect(108, 16, 8, 16, WHITE);
display.display();
} else {
display.fillRect(108, 16, 8, 16, BLACK);
display.drawRect(108, 16, 8, 16, WHITE);
display.display();
}
//Amp 2
if (Amp_2State == HIGH) {
// turn Amp 2 on:
display.fillRect(120, 16, 8, 16, WHITE);
display.display();
} else {
display.fillRect(120, 16, 8, 16, BLACK);
display.drawRect(120, 16, 8, 16, WHITE);
display.display();
}
}