forked from aed3/PS4-esp32
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ability to send data to controller
- Loading branch information
Showing
10 changed files
with
163 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include <PS4Controller.h> | ||
|
||
int r = 255; | ||
int g = 0; | ||
int b = 0; | ||
|
||
// Calculates the next value in a rainbow sequence | ||
void nextRainbowColor() { | ||
if(r > 0 && b == 0){ | ||
r--; | ||
g++; | ||
} | ||
if(g > 0 && r == 0){ | ||
g--; | ||
b++; | ||
} | ||
if(b > 0 && g == 0){ | ||
r++; | ||
b--; | ||
} | ||
} | ||
|
||
void setup() | ||
{ | ||
Serial.begin(9600); | ||
PS4.begin("03:03:03:03:03:03"); | ||
Serial.println("Ready."); | ||
} | ||
|
||
void loop() | ||
{ | ||
if (PS4.isConnected()){ | ||
nextRainbowColor(); | ||
|
||
// Sets the color of the controller's front light | ||
// Params: Red, Green,and Blue | ||
// See here for details: https://www.w3schools.com/colors/colors_rgb.asp | ||
PS4.setLed(r, g, b); | ||
|
||
// Sets how fast the controller's front light flashes | ||
// Params: How long the light is on in ms, how long the light is off in ms | ||
// Range: 0->2550 ms, Set to 0,0 for the light to remain on | ||
PS4.setFlashRate(1000, 1000); | ||
|
||
// Sets the rumble of the controllers | ||
// Params: Weak rumble intensity, Strong rumble intensity | ||
// Range: 0->255 | ||
PS4.setRumble(100, 0); | ||
|
||
// Sends data set in the above three instructions to the controller | ||
PS4.sendToController(); | ||
|
||
// Don't send data to the controller immediately, will cause buffer overflow | ||
delay(10); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.