Hello,
when i try to compile the following code for photon in the WebIDE and i get many compiler errors and i don´t now, the fault…
I need help!
Thanks…
The Code:
Source: Hackster.io Pan-Tilt Controller Using Particle Photon and Bluetooth
#define bufferSize 1024
#define panServoPin D0
#define tiltServoPin D1
#define panServoMin 800
#define panServoMax 2255
#define tiltServoMin 755
#define tiltServoMax 2240
byte buffer[bufferSize];
const char delimiters[3] = ",|";
int bytesRead;
USARTSerial& buletoothSerial = Serial1;
Servo panServo;
Servo tiltServo;
void setup() {
buletoothSerial.begin(9600);
panServo.attach(panServoPin);
tiltServo.attach(tiltServoPin);
// Center the Servos
panServo.writeMicroseconds(1528);
tiltServo.writeMicroseconds(1498);
}
void loop() {
while (buletoothSerial.available() > 0) {
byte byt = buffer[bytesRead] = buletoothSerial.read();
buffer[bytesRead] = byt;
bytesRead++;
if (byt == 124)
{
char* tempPayload = (char*)malloc(bytesRead + 1);
memcpy(tempPayload, buffer, bytesRead);
tempPayload[bytesRead] = NULL;
bytesRead = 0;
double panValue = strtod(strtok(tempPayload, delimiters), NULL);
double tiltValue = strtod(strtok(NULL, delimiters), NULL);
free(tempPayload);
panValue = constrain(panValue, panServoMin, panServoMax);
tiltValue = constrain(tiltValue, tiltServoMin, tiltServoMax);
panServo.writeMicroseconds(panValue);
tiltServo.writeMicroseconds(tiltValue);
}
Particle.process();
}
}
and the errors:
bluetooth_controller.cpp:1:20: error: expected ',' or '...' before numeric constant
#define bufferSize 1024
^
../platform/MCU/shared/STM32/inc/flash_access.h:67:69: note: in expansion of macro 'bufferSize'
int FLASH_Update(const uint8_t *pBuffer, uint32_t address, uint32_t bufferSize);
^
bluetooth_controller.cpp:1:20: error: expected ',' or '...' before numeric constant
#define bufferSize 1024
^
../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc/hw_config.h:114:57: note: in expansion of macro 'bufferSize'
uint32_t Compute_CRC32(const uint8_t *pBuffer, uint32_t bufferSize);
^
bluetooth_controller.cpp:1:20: error: expected ',' or '...' before numeric constant
#define bufferSize 1024
^
../hal/inc/core_hal.h:143:66: note: in expansion of macro 'bufferSize'
uint32_t HAL_Core_Compute_CRC32(const uint8_t *pBuffer, uint32_t bufferSize);
^
bluetooth_controller.cpp: In function 'void loop()':
bluetooth_controller.cpp:40:36: warning: converting to non-pointer type 'char' from NULL [-Wconversion-null]
^
make[1]: *** [../build/target/user/platform-6bluetooth_controller.o] Error 1
make: *** [user] Error 2
Error: Could not compile. Please review your code.