hey,
I have a friend who's a crack at C and he had a look at the code of the render.cpp I had
Here's an outline what he proposed:
in the original code, libpd start message is at the beginning of render:
void render(BelaContext *context, void *userData)
{
int num;
libpd_start_message(8); //get data from all 8 MPR121 pins
for(int n = 0; n < 8; ++n)
libpd_add_float(sensorValue[n]);
libpd_finish_list("sensorValue");
libpd_finish_message("pd", "dsp");
His proposal:
"Try to combine the 'float' and add_float from with the code in render, and put it at the VERY END of render() but inside render, remove the for loop from readMPR121."
libpd_start_message(8); //get data from all 8 MPR121 pins
for(int n = 0; n < 8; ++n){
libpd_add_float(sensorValue[n]);
}
libpd_finish_list("sensorValue");
libpd_finish_message("pd", "dsp");
libpd_start_message(8); //get data from all 8 MPR121 pins
for(int n = 0; n < 8; ++n){
libpd_add_float((float)n);
}
libpd_finish_list("sensorIndex");
libpd_finish_message("pd", "dsp");
OLD read at the end of render.cpp:
void readMPR121(void*)
{
for(int i = 0; i < NUM_TOUCH_PINS; i++) {
sensorValue[i] = -(mpr121.filteredData(i) - mpr121.baselineData(i));
sensorValue[i] -= threshold;
if(sensorValue[i] < 0)
sensorValue[i] = 0;
libpd_float("sensorIndex", (float)i);
//rt_printf("%d ", sensorIndex[i]); //error: use of undeclared identifier 'sensorIndex'
libpd_float("sensorValue", (float)sensorValue[i]);
#ifdef DEBUG_MPR121
rt_printf("%d ", sensorValue[i]); //prints the values of the sensor when DEBUG_MPR121 is define at beginning of programme
#endif
}
#ifdef DEBUG_MPR121
rt_printf("\n");
#endif
// You can use this to read binary on/off touch state more easily
//rt_printf("Touched: %x\n", mpr121.touched());
-----> NEW read:
void readMPR121(void*){
for(int i = 0; i < NUM_TOUCH_PINS; i++) {
sensorValue[i] = -(mpr121.filteredData(i) - mpr121.baselineData(i));
sensorValue[i] -= threshold;
if(sensorValue[i] < 0)
sensorValue[i] = 0;
#ifdef DEBUG_MPR121
rt_printf("%d ", sensorValue[i]); //prints the values of the sensor when DEBUG_MPR121 is define at beginning of programme
#endif
}
#ifdef DEBUG_MPR121
rt_printf("\n");
#endif
// You can use this to read binary on/off touch state more easily
//rt_printf("Touched: %x\n", mpr121.touched());
}
It WORKS!
Also with the little piece of handwoven e-textile (80% polyester, 20%stainless steel)
(image is green because of curtains - heatwave)
Latest render.cpp is here - it desperately needs a clean-up.
https://framabin.org/p/?79ecd118364dce6a#PgFmcFomCItZkIJRkx5azj8hnZuxZs4f76OEgMIOefk=
(you need javascript to decrypt)
End of August - beginning of September I will write about this in full detail and post the project.