Auch für mich ist es nach mehr als 40 jahren weg von der Uni schwierig mit C wieder an zu fangen und ich hoffe, dass Ihr mir helfen könnt.
Ich konstruiere zur Zeit ein morse trainingsgerät in Hardware und Software, das problem was ich habe liegt in der Steuerung des I2C displays,
[code]
#include <Wire.h>
#include <hd44780.h> // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header
String mycall = ""; //
String opname = "";
#define pulsehigh(pin) {digitalWrite(pin, HIGH);delay(200); digitalWrite(pin, LOW); } // Write macro
hd44780_I2Cexp lcd(0x3f, 20, 4);
String selectstrings = "abcdefghijklmnopqrstuvwxyz1234567890 ";
String val1 = "";
String menustring1 = " Operator Name? ";
String menustring2 = " Operator Callsign?";
String spaces = " ";
int maxsize = 37;
int negative = -37;
unsigned int selectIndex = 0;
int col = 0;
int row = 0;
#define leftpin 0
#define selectpin 1
#define rightpin 2
#define menupin 3
#define sound 14
#define ledpin 13
#define led1 A1
#define led2 A2
#define led3 A3
#define led4 A4
int ledstate = 1;
int count = 0;
int oldcount = 0;
int menuselect = 1;
static int state1 = 1; // 1 because of pull-ups on encoder switch
static int oldstate1 = 1;
static int state2 = 1;
static int oldstate2 = 1;
static int state3 = 1;
static int oldstate3 = 1;
static int state4 = 1;
static int oldstate4 = 1;
bool issound = 1;
bool flag = false;
void beep() {
tone(sound, 440, 100);
}
void setdisplay() {
if (flag == 0) {
row = 1;
col = 0;
lcd.setCursor(col, row);
for (byte i = 0; i < maxsize; i++) {
lcd.setCursor(col, row);
lcd.print(selectstrings.charAt(i));
col++;
if (col == 19) {
row++;
col = 0;
}
}
}
lcd.setCursor (0, 1);
lcd.blink();
flag = 1;
col = 0;
row = 0;
}
void setdefault() {
if (opname == "") {
opname = "Daniel ";
}
if (mycall == "") {
mycall = "DF5DG ";
}
lcd.setCursor(0, 0);
lcd.print(spaces);
lcd.setCursor(0, 1);
lcd.print(spaces);
lcd.setCursor(0, 2);
lcd.print(spaces);
lcd.setCursor(0, 3);
lcd.print(spaces);
lcd.setCursor(0, 0);
lcd.print(opname);
lcd.print(mycall);
menuselect = 4;
}
void setuser() {
if (flag == 1) {
lcd.cursor();
row = 1;
col = 0;
//col = negative + maxsize;
lcd.print(selectstrings.charAt(count));
lcd.setCursor(col, row);
lcd.setCursor (0, 3);
lcd.print ("row: ");
lcd.print (row);
lcd.print ("Col: ");
lcd.print(col);
lcd.setCursor(col, row);
lcd.blink();
}
}
void setup() {
lcd.init();
lcd.clear();
lcd.backlight();
col = 0;
row = 0;
lcd.cursor();
lcd.setCursor(col, row);
lcd.blink();
Serial.begin(9600);
pinMode (leftpin, INPUT_PULLUP);
pinMode (selectpin, INPUT_PULLUP);
pinMode (rightpin, INPUT_PULLUP);
pinMode (menupin, INPUT_PULLUP);
pinMode (sound, OUTPUT);
pinMode (ledpin, OUTPUT);
pinMode (led1, OUTPUT);
pinMode (led2, OUTPUT);
pinMode (led3, OUTPUT);
pinMode (led4, OUTPUT);
digitalWrite (ledpin, HIGH);
}
void loop () {
if (menuselect == 1) {
setdisplay();
col = 0;
row = 0;
lcd.setCursor(0, 0);
lcd.print (menustring1);
setuser();
}
if (menuselect == 2) {
col = 0;
row = 0;
lcd.setCursor (0, 0);
lcd.print(menustring2);
setdisplay();
}
if (menuselect == 3) {
setdefault();
}
state1 = digitalRead(leftpin);
state2 = digitalRead(selectpin);
state3 = digitalRead(rightpin);
state4 = digitalRead(menupin);
if (state1 != oldstate1) {
if (state1 == 1) {
tone (sound, 440, 100);
//setuser;
if (count > 0) {
digitalWrite (led1, 1);
count--;
}
if (count == 0) {
count = 0;
digitalWrite (led1, 0);
digitalWrite (led3, 1);
}
}
oldstate1 = state1;
}
if (state2 != oldstate2) {
if (state2 == 1) {
tone (sound, 440, 100);
flag = 1;
pulsehigh(led2);
val1 = selectstrings.charAt(count);
if (menuselect == 1) {
opname = opname + val1;
val1 = "";
} else {
mycall = mycall + val1;
val1 = "";
}
}
oldstate2 = state2;
}
if (count == 0) {
digitalWrite (led3, 1);
}
if (state3 != oldstate3) {
if (state3 == 1) {
tone (sound, 440, 100);
//setuser();
if (count < maxsize) {
count++;
col++;
digitalWrite (led3, 1);
if (count > 0) {
digitalWrite (led1, 1);
}
}
if (count == maxsize) {
count = maxsize;
digitalWrite (led3, 0);
digitalWrite (led1, 1);
}
}
oldstate3 = state3;
}
if (state4 != oldstate4) {
if (state4 == 1) {
tone (sound, 440, 100);
menuselect++;
if (menuselect == 5) {
menuselect = 1;
}
}
oldstate4 = state4;
}
}
[/code]
Meine frage: wie kann ichz den blinkende cursor auf das A hinbekommen und ihn dann mittels den tasten verschieben sodass ich den buchstaben darunter selektoeren kann ?