Hello everyone,
I´ve been reading a lot her, since I startet Arduino but just became a writer here recently.
I just bought a 433mhz sender/receiver bundle which works quite well.
In fact I´ve chosen this method to remote-control motors which are attached to another arduino.
My problem is - couldn’t find a solution yet, although searching for hours - that I want the motors to move as long as I press a button.
Here´s a part of my code from the sender:
void setup()
{
Serial.begin(9600); // Debugging only
Serial.println("setup");
vw_set_ptt_inverted(true);
vw_setup(1000); // Bits per sec
vw_set_tx_pin(14); //Transmitter Data Pin to Digital Pin 3
for(int i = 0; i<6 ; i++)
{
pinMode(remotePins[i], INPUT);
digitalWrite(remotePins[i],HIGH);
}
}
void loop()
{
char *msg2;
while(digitalRead(forward) == LOW)//simple button with no external resistor
{
char *msg2 = "1";//send 1 to the receiver
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg2, strlen(msg2));//send the byte to the receiver
vw_wait_tx(); // Wait until the whole message is gone
Serial.println("1");
}
}
Receiver:
void setup()
{
delay(1000);
Serial.begin(9600);
vw_set_ptt_inverted(true);
vw_set_rx_pin(40);
vw_setup(1000);
vw_rx_start();
pinMode(PoM1a, OUTPUT);
pinMode(PoM1b, OUTPUT);
pinMode(PoM2a, OUTPUT);
pinMode(PoM2b, OUTPUT);
}
void loop(void) {
idleMotor_a();
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;
for (i = 0; i < buflen; i++)
{
if(buf[i]=='1')
{
forward_a();
}}}}
void forward_a()
{
//forward
digitalWrite(PoM1b, LOW);
analogWrite(PoM1a, 200);
analogWrite(PoM2b, 200);
digitalWrite(PoM2a, LOW);
}
Unfortunately the motor stop repeatedly in short intervals. I´d like to solve this in order to make the motors turn as long as I press the button and stop as soon as I release.
I´ve only found solutions for bluetooth, which I don’t want to use yet.
Can anyone give me a hint (or a solution :-)).
Greetings
Norman