-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDFpong_controller_startTemplate
More file actions
106 lines (76 loc) · 3.03 KB
/
DFpong_controller_startTemplate
File metadata and controls
106 lines (76 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*********************************************************************
* DF Pong Controller
*
* This program implements a Bluetooth Low Energy controller for Pong.
* It sends movement data to a central device running in the browser and
* provides audio feedback through a buzzer.
*
* Game Link : https://digitalfuturesocadu.github.io/df-pong/
*
* Movement Values:
* 0 = No movement / Neutral position
* 1 = UP movement (paddle moves up)
* 2 = DOWN movement (paddle moves down)
* 3 = Handshake signal (used for initial connection verification)
*
* Key Functions:
* - handleInput(): Process the inputs to generate the states
* - sendMovement(): Sends movement data over BLE (0-3)
* - updateBLE(): Handles BLE connection management and updates
* - updateBuzzer(): Provides different buzzer patterns for different movements
*
* Key Variables:
* - currentMovement: Stores current movement state (0-2)
* - deviceName : GIVE YOUR DEVICE AN APPROPRIATE NAME
* - LED_PIN : It is important to see the status of the arduino through the LED.
if you can see the built-in add an external one and update the pin it is connected to
*
*********************************************************************/
#include <ArduinoBLE.h>
#include "ble_functions.h"
#include "buzzer_functions.h"
//Since code is split over multiple files, we have to include them here
// ============================================
// IMPORTANT: SET YOUR DEVICE NUMBER HERE (1-25)
// ============================================
const int DEVICE_NUMBER = 0; // ← CHANGE THIS TO YOUR ASSIGNED NUMBER!
// ============================================
// Device name is generated from device number
String deviceNameStr = "DFPONG-" + String(DEVICE_NUMBER);
const char* deviceName = deviceNameStr.c_str();
// Pin definitions buzzer/LED
const int BUZZER_PIN = 11; // Pin for haptic feedback buzzer
const int LED_PIN = LED_BUILTIN; // Status LED pin
// Movement state tracking
int currentMovement = 0; // Current movement value (0=none, 1=up, 2=down, 3=handshake)
void setup()
{
Serial.begin(9600);
// DO NOT use while(!Serial) - it blocks startup without Serial Monitor
// Small delay allows Serial Monitor to catch output if connected
delay(1000);
Serial.println("=== DF Pong Controller Starting ===");
// Configure LED for connection status indication
pinMode(LED_PIN, OUTPUT);
// Initialize Bluetooth Low Energy with device name, number, and status LED
setupBLE(deviceName, DEVICE_NUMBER, LED_PIN);
// Initialize buzzer for feedback
setupBuzzer(BUZZER_PIN);
}
void loop()
{
// Update BLE connection status and handle incoming data
updateBLE();
//read the inputs te determine the current state
//results in changing the value of currentMovement
handleInput();
//send the movement state to P5
sendMovement(currentMovement);
//make the correct noise
updateBuzzer(currentMovement);
}
void handleInput()
{
//put code here that reads the sensor input
//and assigns currentMovement(0=stop, 1=up, 2=down)
}