Go Down

Topic: Need help correcting the error in the code (Read 328 times) previous topic - next topic

yaantey

Given is the code and I am having getting an error "invalid conversion from 'const char' to 'char'. What I want to do is, pass the value to  function.

Quote
//--------------------------------------------------------------------------------------
// Tx Code
// Wireless Force Sensor
// By Yaameen Faisal
//--------------------------------------------------------------------------------------

#include <VirtualWire.h>              // Include VirtualWire library for wireless transmission
int fsrPin = 1;       // define pin A0 as FSR pin
int analog[8];        // define array to get multiple analog readings
int voltage[8];       // define array to get multiple voltage readings
int j;
int awakeCount = 0, restlessCount = 0, asleepCount = 0 ;  // define and initialise counters

void setup()
{
  Serial.begin(9600);        // setup serial communication with baud rate (bits per second) to diplay on serial monitor
  pinMode(fsrPin, INPUT);    // set pin A0 as input
}

void loop()
{
  for(j=0; j<=7; j++)
  {
    analog[j] = analogRead(fsrPin);                  // read pin A0, 8 times
    Serial.print("Analog Reading = ");
    Serial.print(analog[j],DEC);
   
    voltage[j] = map(analog[j], 0, 1023, 0, 5000);   // convert analog reading (0-1023) to voltage (0-5V)
    Serial.print(", Voltage in mV = ");
    Serial.print(voltage[j],DEC);
   
    if (voltage[j] >= 3500)                            //check if voltage >= 3500, if so restless counter = +1
    {
      restlessCount = restlessCount + 1;
    }
    else if (voltage[j] > 1500 && voltage[j] < 3500)  //check if 1500 < voltage < 3500, if so awake counter = +1
    {
      awakeCount = awakeCount + 1;
    }
    else if (voltage[j] > 100 && voltage[j] <= 1500)  //check if 100 < voltage <= 1500, if so asleep counter = +1
    {
      asleepCount = asleepCount + 1;
    }
   
    Serial.print(", Awake count = ");
    Serial.print(awakeCount, DEC);
    Serial.print(", Restless count = ");
    Serial.print(restlessCount, DEC);
    Serial.print(", Asleep count = ");
    Serial.println(asleepCount, DEC);
   
    delay (3000);
  }
   
    int asleepcountLed = asleepCount;      // store asleep counter value in alseepcountLED
    int awakecountLed = awakeCount;        // store awake counter value in awakecountLED
    int restlesscountLed = restlessCount;  // store restless counter value in restlesscountLED
    Serial.println("-----------------------------------------------------------------------");
   
    if (asleepcountLed > awakecountLed && asleepcountLed > restlesscountLed)         // if asleep > awake & asleep > restless, led = green colour
    {
      const char *data = "g";                                ("ERROR IS HERE, BUT I DONT KNOW HOW TO CORRECT IT)
      msgsend(data);                                                 
    }
   
    asleepCount =0;       // reset asleep counter
    awakeCount = 0;       // reset awake counter
    restlessCount = 0;    // reset restless counter
   
    delay (500);
}

void msgsend(char msg)
{
  vw_send((uint8_t *)msg, strlen(msg));
  vw_wait_tx();
}

CrossRoads

I can help with part - use single quotes here

const char *data = "g";

Not how to get from the example
Code: [Select]

void loop()
{
const char *msg = "hello";
vw_send((uint8_t *)msg, strlen(msg));
delay(400);
}

to what you are doing
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

PaulS


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy