Pages: [1]   Go Down
Author Topic: Need help correcting the error in the code  (Read 282 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 213
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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();
}
Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 534
Posts: 26970
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I can help with part - use single quotes here

const char *data = "g";

Not how to get from the example
Code:
void loop()
{
const char *msg = "hello";
vw_send((uint8_t *)msg, strlen(msg));
delay(400);
}
to what you are doing
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 611
Posts: 49101
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Stick with one thread!!!!
Logged

Pages: [1]   Go Up
Jump to: