Does not name a type error

Im trying to compile some code i wrote for the photon to run on my electron but i am getting “does not name a type” errors. I know my code is a mess but the simple functions i am calling should work at least, it runs fine on my photon. Im running 0.5.1 firmware on my particle electron with the 4.0 Blynk library. Any help would be appreciated, thanks.


    cruiserelectronce2.cpp:350:1: error: 'mainRaw' does not name a type
     mainRaw = analogRead(A0);   //main battery voltage
     ^

    cruiserelectronce2.cpp:351:1: error: 'auxRaw' does not name a type
     auxRaw = analogRead(A1);    //aux battery voltage
     ^

    cruiserelectronce2.cpp:352:1: error: 'accRaw' does not name a type
     accRaw = analogRead(A2);    //acc battery voltage
     ^

    cruiserelectronce2.cpp:353:1: error: 'lightRaw' does not name a type
     lightRaw = analogRead(A5);  //ambient light sensor
     ^

    cruiserelectronce2.cpp:359:1: error: 'main' does not name a type
     main = map(mainRaw, 0, 4096, 0, 1865);
     ^

    cruiserelectronce2.cpp:360:1: error: 'aux' does not name a type
     aux = map(auxRaw, 0, 4096, 0, 1865);
     ^

    cruiserelectronce2.cpp:361:1: error: 'acc' does not name a type
     acc = map(accRaw, 0, 4096, 0, 1865);
     ^

    cruiserelectronce2.cpp:362:1: error: 'light' does not name a type
     light = map(lightRaw, 0, 4050, 1100, 1500);
     ^

    cruiserelectronce2.cpp:366:1: error: 'main' does not name a type
     main = (main / 100);
     ^

    cruiserelectronce2.cpp:367:1: error: 'aux' does not name a type
     aux = (aux / 100);
     ^

    cruiserelectronce2.cpp:368:1: error: 'acc' does not name a type
     acc = (acc / 100);
     ^

    cruiserelectronce2.cpp:369:1: error: 'light' does not name a type
     light = (light / 100);
     ^

    cruiserelectronce2.cpp:371:1: error: 'Blynk' does not name a type
     Blynk.virtualWrite(10, main);
     ^

    cruiserelectronce2.cpp:372:1: error: 'Blynk' does not name a type
     Blynk.virtualWrite(11, aux);
     ^

    cruiserelectronce2.cpp:373:1: error: 'Blynk' does not name a type
     Blynk.virtualWrite(12, acc);
     ^

    make[1]: *** [../build/target/user/platform-10cruiserelectronce2.o] Error 1
    make: *** [user] Error 2
    Ready.



    //#pragma SPARK_NO_PREPROCESSOR
    #include "blynk/blynk.h"
    #include "blynk/BlynkSimpleParticle.h"
    #include "SparkCorePolledTimer/SparkCorePolledTimer.h"
    #include "spark-dallas-temperature/spark-dallas-temperature.h"
    #include "OneWire/OneWire.h"
    #include "MCP23008-I2C/MCP23008-I2C.h"  //I2C STUFF
    #include "Adafruit_DHT/Adafruit_DHT.h"
    #define ONE_WIRE_BUS D2                 // Data wire is plugged into pin D2 on the particle
    #define TEMPERATURE_PRECISION 12        // DS18B20 Thermometer Stuff
    #define DHT1PIN C0         // what pin we're connected to
    #define DHT2PIN C1        // what pin we're connected to
    #define DHT1TYPE DHT22		// DHT 22 (AM2302)
    #define DHT2TYPE DHT22		// DHT 22 (AM2302)

    STARTUP(cellular_credentials_set("broadband", "", "", NULL));
    //WidgetLED led1(V31);    //BLYNK LED WIDGET on bluetooth connected
    //WidgetLED led2(V30);    //BLYNK LED WIDGET off bluetooth not connected
    //WidgetLED led3(V29);    //BLYNK LED WIDGET true 29 always on for some reason
    //WidgetLED led4(V28);    //BLYNK LED WIDGET false
    //WidgetLED led5(V27);    //BLYNK LED WIDGET false

    //const int pinTrig = D6;                 //bt signal in on D6
    //const     uint32_t msBlinking = 2000;   //bt LED needs to be lit more than
    //volatile  uint32_t msLastTrig;          //bt trigger 
    //bool connected;                         //bt low not connected, high is connected, 
    //
    //bool locked;        //low locked, high unlocked                         
    //bool running;       //low running, high not running
    //int motionOut = 3;  //low motionOut, high no motion on D3
    //int motionIn = 4;   //low motionIn, high no motion on D4
    //int motion1 = 0;    // variable to store the read value for motionOut
    //int motion2 = 0;    // variable to store the read value for motionIn

    //if locked = true && running = true && motionOut = true && connected = true then unlock
    //if locked = true && running = false && motionOut = true && connected = true then unlock
    //if locked = false && running = true && motionOut = true && connected = false then lock
    //if locked = false && running = false && motionOut = true && connected = false then lock



    //if motion = true, turn on bluetooth for 10 seconds
    //if connected = true && locked = true, then unlock
    //if connected = false && locked = fase, then lock




    //need visual motion sensor to turn on high frequency motion sensor?
    //or of car goes from an on state to off state turn on motion

    //int lastAccState = LOW;   // acc previous state
    //int threshold = 500;   // acc truck is running threshold value
     
    //const int moTrig = D4;                  //motion signal in on D4 
    //const     uint32_t msMotion = 500       //motion signal to be low more than xxx gets rid of false triggers
    //volatile  uint32_t msMotTrig;           //motion trigger

    //int motionOut = 4;                  //motion sensed returns 0 or 1
    //int motionIn = 3;
    //int out = 0;
    //int in = 0;





    //bool locked;                            //door lock returns 0 or 1

    //OneWire oneWire(ONE_WIRE_BUS);          // DS18B20 Thermometer Stuff
    //DallasTemperature sensors(&oneWire);    // DS18B20 Thermometer Stuff
    Adafruit_MCP23008 mcp;                  // I2C STUFF
    SparkCorePolledTimer updateTimer(5000); //Create a timer object and set it's timeout in milliseconds 180K = 5 minutes 
    void OnTimer(void);                     //Prototype for timer callback method

    float main, mainRaw, aux, auxRaw, acc, accRaw, light, lightRaw;
    float h1, t1;
    //float h1, t1, h2, t2;
    DHT dht1(DHT1PIN, DHT1TYPE);
    //DHT dht2(DHT2PIN, DHT2TYPE);

    //float bt, btRaw;

    //define temp address
    //DeviceAddress Thermometer1 = { 0x28, 0xFF, 0x44, 0x50, 0x16, 0x15, 0x3, 0xC };      //outside temp
    //DeviceAddress Thermometer2 = { 0x28, 0xFF, 0xD5, 0x4D, 0x16, 0x15, 0x3, 0xD3 };     //inside temp
    //DeviceAddress Thermometer3 = { 0x28, 0xFF, 0x2D, 0x37, 0x16, 0x15, 0x3, 0xF8 };     //fridge temp
    //DeviceAddress Thermometer4 = { 0x28, 0xFF, 0x6A, 0x24, 0x16, 0x15, 0x3, 0xF0 };     //spare temp

    // define temp bit resolution ie: int, float, double
    //double InTempC = -1;    //this line could probably get deleted, also 0 instead of -1
    //double Temp1 = -1;
    //double Temp2 = -1; 
    //double Temp3 = -1;
    //double Temp4 = -1;
    //void update18B20Temp(DeviceAddress deviceAddress, double &tempC);
    //end temp stuff



    //bt trigger stuff
    //void trig()
    //{
    //  msLastTrig = millis();    //bt trigger timing
    //  msMotTrig = millis();     //motion trigger timing
    //}




     //setupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetup 
    void setup()
    {
    Serial.begin(9600);
    Blynk.begin("7d00133276504bf2b36b871f52266b8c", IPAddress(45,55,130,102), 8442);    //blynk token with electron address
    //Blynk.begin(auth);          // BLYNK initialization
    updateTimer.SetCallback(OnTimer);
    //Particle.function("lock", lock);
    //Particle.function("unlock", unlock);
    Particle.keepAlive(20);     //number of seconds between keep alive pings. Each ping uses 121 bytes of data

    //pinMode(pinTrig, INPUT);                    //bt trigger 
    //attachInterrupt(pinTrig, trig, FALLING);    //bt trigger



    //pinMode(motionOut, INPUT);                    //motion trigger 
    //attachInterrupt(moTrig, trig, FALLING);    //motion trigger
    //pinMode(motionIn, INPUT);                    //motion trigger 
    //attachInterrupt(moTrig, trig, FALLING);






    //sensors.begin();            // DS18B20 initialization
    //sensors.setResolution(Thermometer1, TEMPERATURE_PRECISION);
    //sensors.setResolution(Thermometer2, TEMPERATURE_PRECISION); 
    //sensors.setResolution(Thermometer3, TEMPERATURE_PRECISION);
    //sensors.setResolution(Thermometer4, TEMPERATURE_PRECISION);

    dht1.begin();
    //dht2.begin();
       




    pinMode(A0, INPUT);         //main battery voltage
    pinMode(A1, INPUT);         //aux battery voltage
    pinMode(A2, INPUT);         //acc voltage use to tell if vehicle is running
    //pinMode(A3, INPUT);       //spare
    //pinMode(A4, INPUT);       //spare
    pinMode(A5, INPUT);         //ambient light sensor
    //pinMode(A6, INPUT);       //spare
    //pinMode(A7, INPUT);       //spare


    //pinMode(D0, INPUT);       //used by I2C Relays DO NOT ENABLE
    //pinMode(D1, INPUT);       //used by I2C Relays DO NOT ENABLE
    //pinMode(D2, INPUT);       //used by TEMP Sensors DO NOT ENABLE
    //pinMode(D3, INPUT_PULLUP);  //inner motion trigger pulled high
    //pinMode(D4, INPUT_PULLUP);  //outer motion trigger pulled high
    //pinMode(D5, OUTPUT);       //spare / inner motion
    //pinMode(D6, INPUT);       //used by BT photoresistor DO NOT ENABLE
    //pinMode(D7, OUTPUT);        //shows visual of connection boolean, outer motion
    //pinmode(lock, OUTPUT);
    //pinmode(unlock, OUTPUT);



    // I2C STUFF
    mcp.begin();      // use default address 0
      mcp.pinMode(0, OUTPUT); 
      mcp.pinMode(1, OUTPUT);
      mcp.pinMode(2, OUTPUT);
      mcp.pinMode(3, OUTPUT);
      mcp.pinMode(4, OUTPUT);
      mcp.pinMode(5, OUTPUT);
      mcp.pinMode(6, OUTPUT);
      mcp.pinMode(7, OUTPUT);
    // END I2C STUFF
    }// END VOID SETUP

    // BLYNY WRITE NEEDS TO BE ABOVE LOOP BUT NOT IN SETUP LIKE THIS
    // I2C STUFF
    BLYNK_WRITE(0) {                        //bluetooth power
        if (param.asInt()) {
            mcp.digitalWrite(0, HIGH);
        } else {
           mcp.digitalWrite(0, LOW);}}
           
    BLYNK_WRITE(1) {                        //start/stop
        if (param.asInt()) {
            mcp.digitalWrite(1, HIGH);
            delay(3000);         
        } else {
           mcp.digitalWrite(1, LOW);}}
           
    BLYNK_WRITE(2) {                        //spare - used for calibrating motion sensor
        if (param.asInt()) {
            mcp.digitalWrite(2, HIGH);
        } else {
           mcp.digitalWrite(2, LOW);}}
           
    BLYNK_WRITE(3) {                        //windows vent  
        if (param.asInt()) {
            mcp.digitalWrite(3, HIGH);
        } else {
           mcp.digitalWrite(3, LOW);}}
           
    BLYNK_WRITE(4) {                        //windows down
        if (param.asInt()) {
            mcp.digitalWrite(4, HIGH);
        } else {
           mcp.digitalWrite(4, LOW);}}
           
    BLYNK_WRITE(5) {                        //windows up
        if (param.asInt()) {
            mcp.digitalWrite(5, HIGH);
        } else {
           mcp.digitalWrite(5, LOW);}}
           
    BLYNK_WRITE(6) {                        //unlock    
        if (param.asInt()) {
            mcp.digitalWrite(6, HIGH);
            delay(500);   
            mcp.digitalWrite(6, LOW);
            delay(500);  
            mcp.digitalWrite(6, HIGH);
            delay(500); 
        } else {
           mcp.digitalWrite(6, LOW);}}
            
    BLYNK_WRITE(7) {                        //lock
        if (param.asInt()) {
            mcp.digitalWrite(7, HIGH);
            delay(500);   
            mcp.digitalWrite(7, LOW);
            delay(500);  
            mcp.digitalWrite(7, HIGH);
            delay(500); 
        } else {
           mcp.digitalWrite(7, LOW);}}
    //I2C STUFF


    //looplooplooplooplooplooplooplooplooplooplooplooplooplooplooplooplooplooplooplooplooplooplooploop//looplooplooplooplooplooploopl
    void loop()
    {
    Blynk.run();
    updateTimer.Update();

       h1 = dht1.getHumidity();
       t1 = dht1.getTempCelcius();
     //   h2 = dht2.getHumidity();
     //   t2 = dht2.getTempCelcius();

    }

    void OnTimer(void) { //Handler for the timer, will be called automatically
            // DS18B20 change to farenheight and calibrate - change to *1.8 + 32
    //        sensors.requestTemperatures();
    //      update18B20Temp(Thermometer1, InTempC);
    //        Temp1 = (InTempC * 9)/5 + 32;
    //        update18B20Temp(Thermometer2, InTempC);  
    //        Temp2 = (InTempC * 9)/5 + 31.33;  
    //        update18B20Temp(Thermometer3, InTempC);  
    //        Temp3 = (InTempC * 9)/5 + 31.67;  
     //       update18B20Temp(Thermometer4, InTempC);  
    //        Temp4 = (InTempC * 9)/5 + 32; 
            
            
      t1 = ((float) (t1 * 1.8) + 32);   //scale celcius to F
      h1 = ((float) (h1 * 10) / 10.0);  //add a decimal place?
      
     // t2 = ((float) (t2 * 1.8) + 32);   //scale celcius to F
    //  h2 = ((float) (h2 * 10) / 10.0);  //add a decimal place?        
            
     if ( t1 < 100 && t1 > 1) {      //inside temp
        Blynk.virtualWrite(21, t1); 
    }
    if ( h1 < 100 && h1 > 1) {      //outside temp
        Blynk.virtualWrite(22, h1); 
    }
    //if ( t2 < 100 && t2 > 1) {      //inside temp
    //    Blynk.virtualWrite(23, t2); 
    //}
    //if ( h2 < 100 && h2 > 1) {      //outside temp
     //   Blynk.virtualWrite(24, h2); 
    //}
       
         
         
         
            
    //motion1 = digitalRead(motionOut);   // read the input pin only but write only every 5 sec, 
    //motion2 = digitalRead(motionIn);    // read the input pin only but write only every 5 sec, 

    //  digitalWrite(D7, motion1);    // sets the LED to the button's value
    //  digitalWrite(D5, motion2);    // sets the LED to the button's value


    updateTimer.Update();    // new stuff i dont think we need this one
    }

    //void update18B20Temp(DeviceAddress deviceAddress, double &tempC)
    //{
    //tempC = sensors.getTempC(deviceAddress);

    // read temperature and discard reading between 150 and -30, write to blynk - add averaging
    //if ( Temp1 < 150 && Temp1 > -30) {      //inside temp
     //   Blynk.virtualWrite(21, Temp1); 
    //}
    //if ( Temp2 < 150 && Temp2 > -30) {      //outside temp
    //    Blynk.virtualWrite(22, Temp2); 
    //}
    //if ( Temp3 < 150 && Temp3 > -30) {      //fridge temp
    //    Blynk.virtualWrite(23, Temp3);
    //}
    //if ( Temp4 < 150 && Temp4 > -30) {      //spare temp
    //    Blynk.virtualWrite(24, Temp4);
    //}

    // read analog ports and rename for mapping and virtual pin assignment - add averaging
    mainRaw = analogRead(A0);   //main battery voltage
    auxRaw = analogRead(A1);    //aux battery voltage
    accRaw = analogRead(A2);    //acc battery voltage
    lightRaw = analogRead(A5);  //ambient light sensor

    //motionOut = digitalRead(D2);   //outer motion sensor
    //btRaw = analogRead(A4);

    // map analog input scale output
    main = map(mainRaw, 0, 4096, 0, 1865);
    aux = map(auxRaw, 0, 4096, 0, 1865);
    acc = map(accRaw, 0, 4096, 0, 1865);
    light = map(lightRaw, 0, 4050, 1100, 1500);
    //bt = map(btRaw, 300, 3500, 0, 100);

    // correct decimal place for blynk display
    main = (main / 100);
    aux = (aux / 100);
    acc = (acc / 100);
    light = (light / 100);

    Blynk.virtualWrite(10, main);
    Blynk.virtualWrite(11, aux);
    Blynk.virtualWrite(12, acc);
    //Blynk.virtualWrite(13, motionOut);
    //Blynk.virtualWrite(14, connected);
    //Blynk.virtualWrite(15, light);
    //Blynk.virtualWrite(16, D4);
    //Blynk.virtualWrite(17, D3);


    //connected = (digitalRead(pinTrig) && (millis() - msLastTrig > msBlinking)); //bt connected boolean 

    //digitalWrite(D7, connected);    //bt shows visual of connection boolean, not neccessary



    //working BT led code
    //if ( connected == 1) //Bluetooth LED is solid
    //{
    //WidgetLED led1(31); //turn on "on"LED configured on virtual pin 31.
    //led1.on();
    //}
    //else {led1.off();}

    //if ( connected == 0) //Bluetooth LED is blinking or off
    //{
    //WidgetLED led2(30); //turn on "off" LED configured on virtual pin 30
    //led2.on();
    //}
    //else {led2.off();}
    //end BT led code



      

    //}

SOLVED, I was missing a bracket at the end due to messy coding…

1 Like