Jag bygger en panel till min båt, denna har 6st "vanliga" strömbrytare samt 2st små oled displayer för att visa bränsle och trim nivå (där var ursprungsplanen)
Men nu har jag inkluderat motortemp, klocka, varning om motortemp blir för hög, mm. samt kunna visa vad varje knapp gör genom att toucha på en av brytarna (som är i rostfritt), även kunna växla mellan de olika funktionerna (sidorna) genom att toucha ramen runt som är i aluminium.
mao en liten färddator för min båt.
Jag har än så länge fått båda displayer att fungera, en visar trim, temp, den andra visar bränsle, klocka (finns några saker här med jag skulle vilja justera som jag inte riktigt får till (återkommer till det)
Nu till mitt problem.
Då mina oled displayer (128x32px) inte har någon brygga som jag kan bryta för adresser så var jag tvungen att köra med 2 arduino nano, har inga problem med det förutom att det blev en hel del mer att löda.
Men där kommer problem nr 1.
Jag har bara en mpr121 (med 12 utgångar) för touchstyrning, den kommer att styra visning av knapp 1-6 och vad den knappen gör, och även styra att bläddra mellan funktioner på pin 7 för ramen, det hade ju inte varit några problem om jag bara haft en arduino, men nu har jag ju två, och den funktionen skulle jag vilja ha så att en touch på ramen, så växlar båda arduinos "sida" är detta möjligt, eller måste jag skaffa ytterligare en mpr121?
Prob nr 2.
har googlat som fasen och hittat flera sätt att få en nolla före i min klocka, dvs den visar ex 1.37 men jag vill den ska visa 01.37 men inget av dom funkade, vad fasen gör jag fel? (se sketch)
Prob nr 3
vad är enklast att genomföra så den stannar på ex fuel, men när jag touchar ramen så går den till klocka, och touchar jag igen så kommer jag till nästa "skärm" och till slut tillbaka till fuel?
mm, jag är kanske lite för amatör för att göra nåt sånt här men antar det finns många som kan hjälpa och nu i coronatider ändå inte kan göra nåt annat kreativt
Uppskattar oavsett all hjäp jag kan få.
Så här ser fö kopplingarna ut
https://www.circuito.io/app?components= ... 050,985157
https://www.circuito.io/app?components= ... 989,985157
Kod för display 1 (FUEL)
Kod: Markera allt
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
#define OLED_RESET 4
#define LOGO_WIDTH 128
#define LOGO_HEIGHT 32
#define ONE_WIRE_BUS 2
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
const unsigned char logo_bmp[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x07, 0xFF, 0x8F, 0x00, 0xF1, 0xFF, 0xC1, 0xFF, 0xC3, 0xFF, 0xC7, 0xFF, 0x00, 0x00,
0x00, 0x00, 0x07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F, 0xF8, 0xF0, 0x3E, 0x00, 0x00,
0x00, 0x01, 0xF0, 0x01, 0xFF, 0x3E, 0x3C, 0x00, 0x7C, 0x00, 0x7F, 0xF9, 0xF0, 0x3F, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
void setup() {
Serial.begin(9600);
Wire.begin();
sensors.begin();
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
;
}
Logo();
}
void Logo(void) {
display.clearDisplay();
display.drawBitmap(
(display.width() - LOGO_WIDTH ) / 2,
(display.height() - LOGO_HEIGHT) / 2,
logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, 1);
display.display();
delay(5000);
}
void loop() {
int fuelsensor = analogRead(0);
fuelsensor = map(fuelsensor, 1023, 0, 0, 100);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(56, 3 );
if (fuelsensor < 10)
display.print('0');
display.print(fuelsensor);
display.print("%");
if (fuelsensor < 15) {
display.setCursor(19, 24 );
display.print("FUEL ON RESERVE ");
}
else display.setCursor(35, 24 );
display.print("FUEL LEVEL");
display.fillRect(14, 13, fuelsensor, 5, 1);
display.display();
delay(10000);
display.clearDisplay();
sensors.requestTemperatures();
display.setCursor(4, 10 );
display.setTextSize(2);
display.setTextColor(WHITE);
display.print("ENG: ");
display.print(sensors.getTempCByIndex(0));
display.display();
delay(10000);
}
Kod: Markera allt
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <ds3231.h>
#include "Adafruit_MPR121.h"
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
#define OLED_RESET 4
#define LOGO_WIDTH 128
#define LOGO_HEIGHT 32
#ifndef _BV
#define _BV(bit) (1 << (bit))
#endif
Adafruit_MPR121 cap = Adafruit_MPR121();
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
ts t;
const unsigned char logo_bmp[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0F, 0xFF, 0xF1, 0xF0, 0xFF, 0xFF, 0x00, 0x07, 0xFF, 0xFC, 0x7F, 0xFF, 0x80, 0x00,
0x00, 0x00, 0x0F, 0xFF, 0xE3, 0xF1, 0xFF, 0xFF, 0x00, 0x07, 0xFF, 0xFC, 0x7F, 0xFF, 0x80, 0x00,
0x00, 0x00, 0x1F, 0xFF, 0xE3, 0xF1, 0xFF, 0xFF, 0x00, 0x0F, 0xFF, 0xF8, 0xFF, 0xFF, 0x00, 0x00,
0x00, 0x00, 0x1E, 0x00, 0x01, 0xE3, 0xC0, 0x1E, 0x00, 0x0F, 0x00, 0x00, 0x03, 0xC0, 0x00, 0x00,
0x00, 0x00, 0x1C, 0x00, 0x01, 0xE3, 0xC0, 0x1E, 0x00, 0x0E, 0x00, 0x00, 0x03, 0xC0, 0x00, 0x00,
0x00, 0x00, 0x3F, 0xFF, 0x81, 0xC3, 0x80, 0x1C, 0x00, 0x1E, 0x7F, 0xF0, 0x07, 0x80, 0x00, 0x00,
0x00, 0x00, 0x3F, 0xFF, 0xC3, 0xC7, 0x80, 0x3C, 0x00, 0x1E, 0xFF, 0xF0, 0x07, 0x80, 0x00, 0x00,
0x00, 0x00, 0x3F, 0xFF, 0x83, 0xC7, 0x80, 0x3C, 0x00, 0x1C, 0xFF, 0xE0, 0x07, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3F, 0xFF, 0x83, 0x87, 0x00, 0x38, 0x00, 0x3C, 0xFF, 0xE0, 0x0F, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x07, 0x87, 0x8F, 0x00, 0x78, 0x00, 0x3C, 0x01, 0xE0, 0x0F, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x07, 0x07, 0x8F, 0x00, 0x78, 0x00, 0x3C, 0x01, 0xC0, 0x0E, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFF, 0xFF, 0x07, 0x0F, 0xFF, 0xF0, 0x00, 0x7F, 0xFF, 0xC0, 0x1E, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFF, 0xFF, 0x0F, 0x1F, 0xFF, 0xF0, 0x00, 0x7F, 0xFF, 0xC0, 0x1E, 0x00, 0x00, 0x00,
0x00, 0x01, 0xFF, 0xFE, 0x0F, 0x0F, 0xFF, 0xE0, 0x00, 0x7F, 0xFF, 0x80, 0x1C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
uint16_t lasttouched = 0;
uint16_t currtouched = 0;
void setup() {
Serial.begin(9600);
Wire.begin();
while (!Serial) { // needed to keep leonardo/micro from starting too fast!
delay(10);
}
Serial.println("Adafruit MPR121 Capacitive Touch sensor test");
if (!cap.begin(0x5A)) {
Serial.println("MPR121 not found, check wiring?");
while (1);
}
Serial.println("MPR121 found!");
DS3231_init(DS3231_INTCN);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
;
}
Logo();
Time();
}
void Logo(void) {
display.clearDisplay();
display.drawBitmap(
(display.width() - LOGO_WIDTH ) / 2,
(display.height() - LOGO_HEIGHT) / 2,
logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, 1);
display.display();
delay(5000);
}
void Time(void) {
DS3231_get(&t);
display.clearDisplay();
display.setCursor(4, 10 );
display.setTextSize(2);
display.setTextColor(WHITE);
if (t.mday < 10)
display.print('0');
display.print(t.mday, DEC);
display.print("/");
//if(t.mon<10)
//display.print('0');
display.print(t.mon, DEC);
display.print(" ");
if (t.hour < 10)
display.print('0');
display.print(t.hour, DEC);
display.print(":");
if (t.min < 10)
display.print('0');
display.print(t.min, DEC);
display.display();
delay(3000);
}
void loop() {
int trimsensor = analogRead(0);
trimsensor = map(trimsensor, 1023, 0, 0, 100);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(52, 3 );
display.print("TRIM");
if (trimsensor > 75) {
display.setCursor(27, 24 );
display.print("TRAILER MODE ");
}
else display.setCursor(16, 24 );
display.print("DN <- -> UP");
display.fillRect(14, 13, trimsensor, 5, 1);
display.display();
display.clearDisplay();
currtouched = cap.touched();
for (uint8_t i = 0; i < 12; i++) {
if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
Serial.print(i); Serial.println(" touched");
}
if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) {
Serial.print(i); Serial.println(" released");
}
}
lasttouched = currtouched;
return;
/* if (currtouched[i] == 0) {
switch (i) {
case 0:
//0 was touched
break;
case 1:
//1 was touched
break;
case 2:
//2 was touched
break;
case 3:
//3 was touched
}
*/
}