Add pushbutton test function

This commit is contained in:
Norman Bos
2024-07-13 17:57:03 +02:00
parent 46af1d1b28
commit c22b8ecdf2
+119 -11
View File
@@ -1,7 +1,7 @@
// modified for use with Sony RM-D27M
// based on https://hackaday.io/project/165504-sony-minidisc-namer by smartroad
#include <IRremote.h> // Muss installiert werden. Evtl alte Version. Siehe https://github.com/Arduino-IRremote/Arduino-IRremote
#include <IRremote.h> // Muss installiert werden. Funktioniert mit v2.5.0 Siehe https://github.com/Arduino-IRremote/Arduino-IRremote
#include "defines.h"
IRsend irsend;
@@ -9,24 +9,100 @@ IRsend irsend;
char inputChars[64];
byte charCount = 0;
byte mode = 0; // Capticals = 0, Lowercase = 1
byte mode = 0; // Capitals = 0, Lowercase = 1
byte targetMode = 0;
boolean commandMode = true; // True = control playback | False = name entry mode
int totalCount = 0;
byte blockCount = 0;
// define the IT sendPin:
uint8_t tSendPin = 4; // IO4 auf AZ D1
/* start testing code for hardware button*/
// constants won't change. They're used here to set pin numbers:
uint8_t buttonPin = 14; // the number of the pushbutton pin
uint8_t ledPin = 2; // the number of the LED pin
// variables will change:
uint8_t buttonState = 0; // variable for reading the pushbutton status
/* end testing code */
void setup()
{
Serial.begin(9600);
pinMode(2, OUTPUT);
// Initialize serial monitor:
Serial.begin(115200);
while (!Serial)
;
pinMode(9, OUTPUT);
digitalWrite(9, HIGH);
helpText();
// helpText();
pinMode(tSendPin, OUTPUT);
digitalWrite(tSendPin, LOW);
/* start testing code */
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
digitalWrite(ledPin, HIGH);
/* end testing code */
}
void loop()
{
// blink(); //! Der Loop wird gerade nur einmal ausgeführt und stoppt bei der serial monitor eingabe. Bei jeder Eingabe erfolgt ein neue Loop. Alle test-Funktionen laufen durch.
// simpleButtonTest();
buttonPlayTest();
// oldSerialInput();
}
void simpleButtonTest()
{
/* start testing code */
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH)
{
// write to serial monitor:
Serial.println(F("button state is HIGH"));
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else
{
// turn LED off:
digitalWrite(ledPin, LOW);
}
/* end testing code */
}
void buttonPlayTest()
{
/* start testing code */
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH)
{
// write to serial monitor:
Serial.println(F("button state is HIGH"));
// turn LED on:
digitalWrite(ledPin, HIGH);
Serial.println(F("Play"));
sendButton(PLAY);
}
else
{
// turn LED off:
digitalWrite(ledPin, LOW);
}
/* end testing code */
}
void oldSerialInput()
{
if (commandMode)
@@ -115,12 +191,16 @@ void loop()
else if (serialChar == '1')
{
Serial.print(F("1"));
sendButton(NUMBER1);
// sendButton(NUMBER1);
digitalWrite(ledPin, HIGH);
Serial.print(F("set ledPin HIGH"));
}
else if (serialChar == '2')
{
Serial.print(F("2"));
sendButton(NUMBER2);
// sendButton(NUMBER2);
digitalWrite(ledPin, LOW);
Serial.print(F("set ledPin LOW"));
}
else if (serialChar == '3')
{
@@ -677,13 +757,13 @@ void sendCmd(int command, byte repeats)
void sendButton(int bts)
{
digitalWrite(9, LOW);
digitalWrite(tSendPin, HIGH);
for (int i = 0; i < 3; i++)
{
irsend.sendSony(bts, 12);
irsend.sendSony(bts, 12); //! Hier wird das Command gesendet! Es besteht aus dem command und der bitlänge.
delay(25);
}
digitalWrite(9, HIGH);
digitalWrite(tSendPin, LOW);
}
void sendNumCmd(int command, byte repeats)
@@ -756,3 +836,31 @@ boolean nameCheck()
else
return 0;
}
void blink()
{
/* start testing code */
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH)
{
// write to serial monitor:
Serial.println(F("button state is HIGH"));
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else
{
// turn LED off:
digitalWrite(ledPin, LOW);
}
/* end testing code */
Serial.print(F("blink"));
// digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
// delay(1000); // wait for a second
// digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW
// delay(1000);
}