add table template for table side of code
This commit is contained in:
parent
8fa0623d74
commit
925200252d
2 changed files with 89 additions and 21 deletions
|
@ -1,3 +1,9 @@
|
|||
#include <SoftwareSerial.h>
|
||||
|
||||
// TX/RX
|
||||
SoftwareSerial Bluetooth(10, 9);
|
||||
|
||||
// Button pins
|
||||
int const UP_BTN = 2;
|
||||
int const DOWN_BTN = 4;
|
||||
int const LEFT_BTN = 5;
|
||||
|
@ -8,34 +14,87 @@ int const JOYSTICK_BTN = 8;
|
|||
int const JOYSTICK_AXIS_X = A0;
|
||||
int const JOYSTICK_AXIS_Y = A1;
|
||||
int buttons[] = {UP_BTN, DOWN_BTN, LEFT_BTN, RIGHT_BTN, E_BTN, F_BTN, JOYSTICK_BTN};
|
||||
int line = 1;
|
||||
|
||||
bool halt_packets = false;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.begin(38400);
|
||||
Serial.println("Serial Started");
|
||||
for (int i=0; i < 7; i++) pinMode(buttons[i], INPUT_PULLUP);
|
||||
Serial.println("Finished pin setup");
|
||||
Bluetooth.begin(38400);
|
||||
Serial.println("Send 's' to sniff packets, 'h' to halt packets:");
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
unsigned long pack = 0;
|
||||
|
||||
void loop() {
|
||||
Serial.print(line);
|
||||
Serial.print(". Yeet!\n");
|
||||
// Joystick range is from 0 to 1023
|
||||
// A deadzone of 10 or 20 should be safe.
|
||||
if (!halt_packets) {
|
||||
pack = build_packet();
|
||||
}
|
||||
delay(100);
|
||||
|
||||
Serial.print("UP="),Serial.println(digitalRead(UP_BTN));
|
||||
Serial.print("DOWN="),Serial.println(digitalRead(DOWN_BTN));
|
||||
Serial.print("LEFT="),Serial.println(digitalRead(LEFT_BTN));
|
||||
Serial.print("RIGHT="),Serial.println(digitalRead(RIGHT_BTN));
|
||||
Serial.print("E="),Serial.println(digitalRead(E_BTN));
|
||||
Serial.print("F="),Serial.println(digitalRead(F_BTN));
|
||||
Serial.print("JOYSTICK BTN="),Serial.println(digitalRead(JOYSTICK_BTN));
|
||||
// Read from HC-05 and send data to the Arduino Serial Monitor
|
||||
if (Bluetooth.available()) {
|
||||
if (!halt_packets) {
|
||||
Bluetooth.write(pack);
|
||||
}
|
||||
Serial.write(Bluetooth.read());
|
||||
}
|
||||
|
||||
// Read from Arduino Serial Monitor and send it to the HC-05
|
||||
if (Serial.available()) {
|
||||
char com = Serial.read();
|
||||
Serial.write(com);
|
||||
if (com == 's' && !halt_packets) {
|
||||
Serial.println();
|
||||
PrintBits32(pack);
|
||||
}
|
||||
else if (com == 'h') {
|
||||
Serial.println();
|
||||
Serial.println("!!! Packet generation halted !!!");
|
||||
halt_packets = !halt_packets;
|
||||
}
|
||||
Bluetooth.print(com);
|
||||
}
|
||||
|
||||
// Joystick range is from 0 to 653 +- 1
|
||||
// Center is about 323 +- 2. A deadzone of 10 or 20 should be safe.
|
||||
Serial.print("X: ");
|
||||
Serial.println(analogRead(JOYSTICK_AXIS_X));
|
||||
Serial.print("Y: ");
|
||||
Serial.println(analogRead(JOYSTICK_AXIS_Y));
|
||||
line++;
|
||||
delay(150);
|
||||
}
|
||||
|
||||
unsigned long build_packet(void) {
|
||||
/*
|
||||
* Packets will always contain analog values (10 bits each)
|
||||
* One bit containing high/low value for buttons is included
|
||||
*/
|
||||
unsigned long built_packet = 0;
|
||||
// Start digital input
|
||||
built_packet += digitalRead(UP_BTN);
|
||||
built_packet |= digitalRead(DOWN_BTN) << 1;
|
||||
built_packet += digitalRead(LEFT_BTN) << 2;
|
||||
built_packet += digitalRead(RIGHT_BTN) << 3;
|
||||
built_packet += digitalRead(E_BTN) << 4;
|
||||
built_packet += digitalRead(F_BTN) << 5;
|
||||
built_packet += digitalRead(JOYSTICK_BTN) << 6;
|
||||
// Start analog input
|
||||
built_packet = built_packet << 10;
|
||||
built_packet += analogRead(JOYSTICK_AXIS_X);
|
||||
built_packet = built_packet << 10;
|
||||
built_packet += analogRead(JOYSTICK_AXIS_Y);
|
||||
return built_packet;
|
||||
}
|
||||
|
||||
void PrintBits32(unsigned long u)
|
||||
{
|
||||
char str[34];
|
||||
str[32] = '\n';
|
||||
str[33] = 0;
|
||||
for (int i = 31; i >= 0; i--)
|
||||
{
|
||||
str[i] = '0' + (u & 1);
|
||||
u >>= 1;
|
||||
}
|
||||
|
||||
Serial.print(str);
|
||||
}
|
||||
|
|
9
arduino_maze/arduino_maze.ino
Normal file
9
arduino_maze/arduino_maze.ino
Normal file
|
@ -0,0 +1,9 @@
|
|||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
|
||||
}
|
Loading…
Reference in a new issue