Hello, I have a problem in the coding part.
I will do wireless servo control with muscle sensor
but it keeps giving this error in transmitter.
"void value not ignored as it ought to be"
can you help. footnote: code is attached
sketch_jun20a.ino (1.6 KB)
Your topic was MOVED to its current forum category as it is more suitable than the original
Please post your code here, using code tags when you do
#include <SPI.h>
#include "RF24.h"
#include "Wire.h"
#include "I2Cdev.h"
#include "nRF24L01.h"
#include <Servo.h>
#define THRESHOLD 250
#define EMG_PIN 7
#define SERVO_PIN 9
Servo SERVO_1;
int emo[1];
int muscle[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
void setup(){
Serial.begin(9600);
SERVO_1.attach(SERVO_PIN);
radio.begin();
radio.openWritingPipe(pipe);
}
void loop(){
int value = analogRead(EMG_PIN);
if(value > THRESHOLD){
emo[0] = SERVO_1.write(170);
radio.write(&emo, sizeof(emo));
}
else{
muscle[0] = SERVO_1.write(10);
radio.write(&muscle, sizeof(muscle));
}
Serial.println(value);
}
As to your problem, what value does SERVO_1.write() return ?
int value = analogRead(EMG_PIN); // read the muscle sensor
threshold=250
if(value > THRESHOLD)
emo[0] write 170 degrees
else
muscle[0] write 10 degrees
@emohizli did you deliberately ignore the request to use code tags when posting code ?
Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'
Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination
I have no idea what post #5 is about
muscle[0] = SERVO_1.write(10);
the write() function does not return a value so what were you hoping that it would return ?
There is 1 servo in the system . In the code, the servo has 2 values. rotate 170 degrees if the value read is greater than threshold. else rotate 10 degrees
I repeat
I don't understand what you mean. Can you give some details? My English is not very good.
#include <SPI.h>
#include "RF24.h"
#include "Wire.h"
#include "I2Cdev.h"
#include "nRF24L01.h"
#include <Servo.h>
#define THRESHOLD 250
#define EMG_PIN 7
#define SERVO_PIN 9
Servo SERVO_1;
int emo[1];
int muscle[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
void setup(){
Serial.begin(9600);
SERVO_1.attach(SERVO_PIN);
radio.begin();
radio.openWritingPipe(pipe);
}
void loop(){
int value = analogRead(EMG_PIN);
if(value > THRESHOLD){
emo[0] = SERVO_1.write(170);
radio.write(&emo, sizeof(emo));
}
else{
muscle[0] = SERVO_1.write(10);
radio.write(&muscle, sizeof(muscle));
}
Serial.println(value);
}
muscle[0] = SERVO_1.write(10);
You are trying to get a value that has been returned by the write() function and save it to muscle[0]
Why ?
because I coded the servo in the receiver codes to work with the muscle[0] command
Thank you very much for your help i found the error stay safe
Please post your working code here (in code tags) to help anyone else with a similar problem
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.