Right first things first Hi! I am long time lurker who finally has a question that has bewildered me.
const byte Sad[8] PROGMEM = {
B00000,
B01010,
B01010,
B00000,
B00100,
B00000,
B01110,
B10001
};
const byte Happy[8] PROGMEM = {
B00000,
B01010,
B01010,
B00000,
B00100,
B10001,
B01110,
B00000
};
void setup() {
lcd.createChar_P(0, Sad);
lcd.createChar_P(1, Happy);
}
void loop() {
//loads of other stuff
lcd.clear(); // Clear lcd.
lcdLine1 = "Power LED on?"; // Store last message sent to lcd
lcd.setCursor(justify(lcdLine1), 0); // set cursor to the center of the screen.
lcd.print(lcdLine1); // Write to lcd.
digitalWrite(AuxEn, HIGH); // Turn on aux pcb.
buttonPress(); // Call function
// What was pressed.
switch (Pressed) {
case Yes:
lcd.backlight(); // Turn backlight on.
lcd.clear(); // Clear lcd.
lcd.setCursor(justify("Great!"), 0); // set cursor to the center of the screen.
lcd.print("Great!"); // Write to lcd.
lcd.setCursor(7, 1); // Set to center
lcd.write(1); // print smiley
passed[0] = true; // Store result in array.
delay(1000); // Delay for 1s.
break;
case No:
lcd.backlight(); // Turn backlight on.
lcd.clear(); // Clear lcd.
lcd.setCursor(justify("Oh no!"), 0); // set cursor to the center of the screen.
lcd.print("Oh no!"); // Write to lcd.
lcd.setCursor(7, 1); // Set to center
lcd.write(0); // print smiley
passed[0] = false; // Store result in array.
delay(1000); // Delay for 1s.
break;
}
}
int justify(String string) {
int x;
x = 8 - (string.length() / 2);
return x;
}
// If timed out wait for action, turn off backlight and aux board.
void timedOut() {
// If timed out ask to continue.
while (1) {
// Was yes button pressed and not input.
debouncerYes.update();
if (input == false && debouncerYes.fell()) {
lcd.backlight(); // Turn backlight on.
lcd.clear(); // Clear lcd.
lcd.setCursor(justify(lcdLine1), 0); // set cursor to the center of the screen.
lcd.print(lcdLine1); // Reprint the last message sent to lcd.
lcd.setCursor(justify(lcdLine2), 1); // set cursor to the center of the screen.
lcd.print(lcdLine2); // Reprint the last message sent to lcd.
startMillis = currentMillis; // Store previous trigger time.
digitalWrite(AuxEn, HIGH); // Turn Aux board back on.
return;
}
if (input == true && debouncerYes.fell()) {
inputFailed = true;
startMillis = millis(); // Account for current time
return;
}
// Was no button pressed.
debouncerNo.update();
if (input == false && debouncerNo.fell()) {
lcd.backlight(); // Turn backlight on.
lcd.clear(); // Clear lcd.
asm volatile (" jmp 0"); // Reset.
return;
}
if (input == true && debouncerNo.fell()) {
inputFailed = false;
lcd.setCursor(justify(lcdLine1), 0); // set cursor to the center of the screen.
lcd.print(lcdLine1); // Reprint the last message sent to lcd.
lcd.setCursor(justify(lcdLine2), 1); // set cursor to the center of the screen.
lcd.print(lcdLine2); // Reprint the last message sent to lcd.
startMillis = currentMillis; // Store previous trigger time.
return;
}
}
}
// Wait for button input, polling both buttons will time out in milliseconds (1000 = 1s).
void buttonPress() {
// Loop until returned.
startMillis = millis(); // Account for current time
while (1) {
currentMillis = millis(); // Current up time.
if (currentMillis - startMillis >= timeOut && input == false) {
lcd.noBacklight(); // Turn backlight off.
lcd.clear(); // Clear lcd.
lcd.setCursor(justify("Yes to continue"), 0); // set cursor to the center of the screen.
lcd.print("Yes to continue"); // Write to lcd.
lcd.setCursor(justify("No to restart"), 1); // set cursor to the center of the screen.
lcd.print("No to restart"); // Write to lcd.
digitalWrite(AuxEn, LOW); // Turn of power to DUT.
timedOut(); // Call timedOut
startMillis = currentMillis; // Store previous trigger time.
}
if (currentMillis - startMillis >= timeOut && input == true) {
lcd.clear(); // Clear lcd.
lcd.setCursor(justify("Did to attempt?"), 0); // set cursor to the center of the screen.
lcd.print("Did to attempt?"); // Write to lcd.
timedOut(); // Call timedOut
startMillis = currentMillis; // Store previous trigger time.
}
// Was yes button pressed.
debouncerYes.update();
if (input == false && debouncerYes.fell()) {
Pressed = Yes; // Return yes enum.
return;
}
// Was no button pressed.
debouncerNo.update();
if (input == false && debouncerNo.fell()) {
Pressed = No; // Return no enum.
return;
}
// Was touch triggered.
debouncerTouch.update();
if (input == true && debouncerTouch.fell()) {
Pressed = Pad; // Return touched enum.
return;
}
// Was hall1 triggered.
debouncerHall1.update();
if (input == true && debouncerHall1.fell()) {
Pressed = Pos1; // Return Pos1 enum.
return;
}
// Was hall1 triggered.
debouncerHall2.update();
if (input == true && debouncerHall2.fell()) {
Pressed = Pos2; // Return Pos2 enum.
return;
}
// Did input fail.
if (input == true && inputFailed == true) {
Pressed = Failed; // Return failed enum.
inputFailed = false;
return;
}
}
}
My first question is regardless of whether i write 0 or 1 i always get a smiley face, why?
Second question anyone got a library for the AD5110 or can help me figure out how to talk to it?
Full code here.