Expected initializer before 'servo1'

I have one last detail / complication to understand before my project is finished. The servo Part works when it is a stand alone / all by itself when it is on the UNO, but red lines at line 137. Since it is a servo signal it has to be PWM. Ideas on a way to overcome this challenge will be very welcome. It is the very last piece of my puzzle, Thanks in advance.

// ATtiny85 torch detector
// Author: Nick Gammon
// Date: 25 February 2015

// ATMEL ATTINY 25/45/85 / ARDUINO
// Pin 1 is /RESET
//
//                  +-\/-+
// Ain0 (D 5) PB5  1|    |8  Vcc
// Ain3 (D 3) PB3  2|    |7  PB2 (D 2) Ain1
// Ain2 (D 4) PB4  3|    |6  PB1 (D 1) pwm1
//            GND  4|    |5  PB0 (D 0) pwm0
//                  +----+

/*

  Pin 2 (PB3) <-- LDR (GL5539) --> Pin 7 (PB2) <----> 56 k <----> Gnd

  Pin 5 (PB0) <---- LED ---> 100 R <-----> Gnd

*/


#include <avr/sleep.h>    // Sleep Modes
#include <avr/power.h>    // Power management
#include <avr/wdt.h>      // Watchdog timer
#include <Servo.h>
Servo servo1;
int servoPin = 9;

const byte POWER_PIR = 7;          
const byte PIR_SIGNAL = 12;
int val = 0;
const byte LED = 13;
const byte LDR_ENABLE = 8;   
const byte LDR_READ = A0;     
const int LIGHT_THRESHOLD = 200;  // Flash LED when darker than this

// when ADC completed, take an interrupt
EMPTY_INTERRUPT (ADC_vect);

float getReading (byte port)       // Take an ADC reading in sleep mode (ADC)
{
  power_adc_enable() ;
  ADCSRA = bit (ADEN) | bit (ADIF);  // enable ADC, turn off any pending interrupt

  // set a2d prescale factor to 128
  // 8 MHz / 128 = 62.5 KHz, inside the desired 50-200 KHz range.

  ADCSRA |= bit (ADPS0) | bit (ADPS1) | bit (ADPS2);

  if (port >= A0)
    port -= A0;

#if defined(__AVR_ATmega328P__)

  ADMUX = bit (REFS0) | (port & 0x07); // AVcc

#endif

  noInterrupts ();
  set_sleep_mode (SLEEP_MODE_ADC);    // sleep during sample
  sleep_enable();

  // start the conversion
  ADCSRA |= bit (ADSC) | bit (ADIE);
  interrupts ();
  sleep_cpu ();
  sleep_disable ();

  // reading should be done, but better make sure
  // maybe the timer interrupt fired

  // ADSC is cleared when the conversion finishes
  while (bit_is_set (ADCSRA, ADSC))
  { }

  byte low  = ADCL;
  byte high = ADCH;

  ADCSRA = 0;  // disable ADC
  power_adc_disable();

  return (high << 8) | low;

}  // end of getReading

// watchdog interrupt
ISR (WDT_vect)
{
  wdt_disable();  // disable watchdog
}  // end of WDT_vect

#if defined(__AVR_ATmega328P__)                                
#define watchdogRegister WDTCSR
//#else
// #define watchdogRegister WDTCSR
#endif

void setup ()
{
  wdt_reset();
  pinMode (POWER_PIR, OUTPUT);
  pinMode (LED, OUTPUT);
  servo1.attach(servoPin);
  pinMode (LDR_ENABLE, OUTPUT);
  pinMode (PIR_SIGNAL, INPUT);
  ADCSRA = 0;            // turn off ADC
  power_all_disable ();  // power off ADC, Timer 0 and 1, serial interface
}  // end of setup

void loop ()
{
  // power up the LDR, take a reading
  digitalWrite (LDR_ENABLE, HIGH);

  int value = getReading (LDR_READ);
  // power off the LDR
  digitalWrite (LDR_ENABLE, LOW);

  if (value < LIGHT_THRESHOLD)    // if it's dark, do stuff
  {
    power_timer0_enable ();
    delay (1);  // let timer reach a known point

    digitalWrite (POWER_PIR, HIGH);
  }    else
    digitalWrite (POWER_PIR, LOW);

   { val = digitalRead (PIR_SIGNAL);   // read the input pin
  digitalWrite (LED,val);  // sets the LED to the button's value
  
  val = digitalRead (PIR_SIGNAL);   // read the input pin
  
  void analogWrite(uint8_t, int) 
  
  servo1.write(0);   //degrees
  delay(50);         // delay between moves
  servo1.write(10);
  delay(50);
  servo1.write(0);
  delay(50);
  servo1.write(10);
  delay(50);
  
}
   
  {
    power_timer0_disable ();
  }

  goToSleep ();
}  // end of loop

void goToSleep ()
{
  set_sleep_mode (SLEEP_MODE_PWR_DOWN);
  noInterrupts ();       // timed sequence coming up

  // pat the dog
  wdt_reset();

  // clear various "reset" flags
  MCUSR = 0;
  // allow changes, disable reset, clear existing interrupt
  watchdogRegister = bit (WDCE) | bit (WDE) | bit (WDIF);
  // set interrupt mode and an interval (WDE must be changed from 1 to 0 here)
  watchdogRegister = bit (WDIE) | bit (WDP2) | bit (WDP1) | bit (WDP0);    // set WDIE, and 2 seconds delay

  sleep_enable ();       // ready to sleep
  interrupts ();         // interrupts are required now
  sleep_cpu ();          // sleep
  sleep_disable ();      // precaution
}  // end of goToSleep
        void analogWrite(uint8_t, int)

          servo1.write(0);  //degrees

Missing opening brace on this function

And there are other problems after that function too

other problems?

Actually, looking at it more closely you are trying to define the analogueWrite() function in your sketch

Delete the void data type in the first line of code quoted above and the need for an opening brace will be removed

It's PIR dependent, I tried analogWrite (servo1, val) I. think I am missing the 0-255, I'm missing something. it's supposed to run when the PIR goes high / has an output signal.

val = digitalRead (PIR_SIGNAL);   // read the input pin
  
  //void analogWrite(uint8_t, int) 
  
  servo1.write(0);   //degrees
  delay(50);         // delay between moves
  servo1.write(10);
  delay(50);
  servo1.write(0);
  delay(50);
  servo1.write(10);
  delay(50);

You are missing the point

Because you have added the void data type before the name of the function it looks like you are trying to define the function rather than call the function

Elsewhere in the sketch you have used

        digitalWrite(LED, val);         // sets the LED to the button's value

Oh look. No data type in front of the function name

This is weird....... The servo sketch works fine with the parameters used as a stand alone program. How ever if I comment out all the PIR read, light LED stuff and just include the servo positions with delays it doesn't do anything. Is there perhaps a library conflict?

One more time

HAVE YOU DELETED THE VOID DATA TYPE BEDORE THE "CALL" TO analog(Write) ?

Hang on !

Yet another problem

        void analogWrite(uint8_t, int)

Even if you did remove the void then analogWrite() takes a pin number as its first parameter and an int value as its second parameter

Not quite sure I understand the meaning of that, but this works. the servo is commented out. But is says :

{ val = digitalRead (PIR_SIGNAL); // read the input pin
digitalWrite (LED,val); which basically means if the PIR goes HIGH so does the LED. OR.....our we on 2 completely different pages?

// ATtiny85 torch detector
// Author: Nick Gammon
// Date: 25 February 2015

// ATMEL ATTINY 25/45/85 / ARDUINO
// Pin 1 is /RESET
//
//                  +-\/-+
// Ain0 (D 5) PB5  1|    |8  Vcc
// Ain3 (D 3) PB3  2|    |7  PB2 (D 2) Ain1
// Ain2 (D 4) PB4  3|    |6  PB1 (D 1) pwm1
//            GND  4|    |5  PB0 (D 0) pwm0
//                  +----+

/*

  Pin 2 (PB3) <-- LDR (GL5539) --> Pin 7 (PB2) <----> 56 k <----> Gnd

  Pin 5 (PB0) <---- LED ---> 100 R <-----> Gnd

*/


#include <avr/sleep.h>    // Sleep Modes
#include <avr/power.h>    // Power management
#include <avr/wdt.h>      // Watchdog timer
#include <Servo.h>
Servo servo1;
int servoPin = 9;

const byte POWER_PIR = 7;          
const byte PIR_SIGNAL = 12;
int val = 0;
const byte LED = 13;
const byte LDR_ENABLE = 8;   
const byte LDR_READ = A0;     
const int LIGHT_THRESHOLD = 200;  // Flash LED when darker than this

// when ADC completed, take an interrupt
EMPTY_INTERRUPT (ADC_vect);

float getReading (byte port)       // Take an ADC reading in sleep mode (ADC)
{
  power_adc_enable() ;
  ADCSRA = bit (ADEN) | bit (ADIF);  // enable ADC, turn off any pending interrupt

  // set a2d prescale factor to 128
  // 8 MHz / 128 = 62.5 KHz, inside the desired 50-200 KHz range.

  ADCSRA |= bit (ADPS0) | bit (ADPS1) | bit (ADPS2);

  if (port >= A0)
    port -= A0;

#if defined(__AVR_ATmega328P__)

  ADMUX = bit (REFS0) | (port & 0x07); // AVcc

#endif

  noInterrupts ();
  set_sleep_mode (SLEEP_MODE_ADC);    // sleep during sample
  sleep_enable();

  // start the conversion
  ADCSRA |= bit (ADSC) | bit (ADIE);
  interrupts ();
  sleep_cpu ();
  sleep_disable ();

  // reading should be done, but better make sure
  // maybe the timer interrupt fired

  // ADSC is cleared when the conversion finishes
  while (bit_is_set (ADCSRA, ADSC))
  { }

  byte low  = ADCL;
  byte high = ADCH;

  ADCSRA = 0;  // disable ADC
  power_adc_disable();

  return (high << 8) | low;

}  // end of getReading

// watchdog interrupt
ISR (WDT_vect)
{
  wdt_disable();  // disable watchdog
}  // end of WDT_vect

#if defined(__AVR_ATmega328P__)                                
#define watchdogRegister WDTCSR
//#else
// #define watchdogRegister WDTCSR
#endif

void setup ()
{
  wdt_reset();
  pinMode (POWER_PIR, OUTPUT);
  pinMode (LED, OUTPUT);
  servo1.attach(servoPin);
  pinMode (LDR_ENABLE, OUTPUT);
  pinMode (PIR_SIGNAL, INPUT);
  ADCSRA = 0;            // turn off ADC
  power_all_disable ();  // power off ADC, Timer 0 and 1, serial interface
}  // end of setup

void loop ()
{
  // power up the LDR, take a reading
  digitalWrite (LDR_ENABLE, HIGH);

  int value = getReading (LDR_READ);
  // power off the LDR
  digitalWrite (LDR_ENABLE, LOW);

  if (value < LIGHT_THRESHOLD)    // if it's dark, do stuff
  {
    power_timer0_enable ();
    delay (1);  // let timer reach a known point

   digitalWrite (POWER_PIR, HIGH);
  }    else
    digitalWrite (POWER_PIR, LOW);

   { val = digitalRead (PIR_SIGNAL);   // read the input pin
  digitalWrite (LED,val);  // sets the LED to the button's value
  
  /*val = digitalRead (PIR_SIGNAL);   // read the input pin
  
  //void analogWrite(uint8_t, int) 
  
  servo1.write(0);   //degrees
  delay(50);         // delay between moves
  servo1.write(10);
  delay(50);
  servo1.write(0);
  delay(50);
  servo1.write(10);
  delay(50);*/
  
}
   
  {
    power_timer0_disable ();
  }

  goToSleep ();
}  // end of loop

void goToSleep ()
{
  set_sleep_mode (SLEEP_MODE_PWR_DOWN);
  noInterrupts ();       // timed sequence coming up

  // pat the dog
  wdt_reset();

  // clear various "reset" flags
  MCUSR = 0;
  // allow changes, disable reset, clear existing interrupt
  watchdogRegister = bit (WDCE) | bit (WDE) | bit (WDIF);
  // set interrupt mode and an interval (WDE must be changed from 1 to 0 here)
  watchdogRegister = bit (WDIE) | bit (WDP2) | bit (WDP1) | bit (WDP0);    // set WDIE, and 2 seconds delay

  sleep_enable ();       // ready to sleep
  interrupts ();         // interrupts are required now
  sleep_cpu ();          // sleep
  sleep_disable ();      // precaution
}  // end of goToSleep

When you define a function to be used in a sketch you must specify what data type, if any, the function will return to the calling function. If no data is to be returned then you use the void data type

However, when you call a function you must not precede the function name with a data type otherwise the compiler will think that you are defining the function for which there are different requirements than when you define one

I strongly suggest that you read up on C/C++ functions

was deleted long ago,

reading? It's straight from the Arduino ref library. Only I don't use a button, I use a PIR. I don't understand the confusion. It WORKS LIKE IT SAYS IT WILL! Something wanders in front of the PIR, The PIR sends out a digital signal, which is then read. as a HIGH, and then it turns on the LED. The "signal" from the PIR is set to last for 18 seconds, Then the signal goes low. and it turns off the LED. It isn't the PROBLEM

THE PROBLEM IS THE SERVO INSTRUCTIONS WHICH HAVE TO BE IMPLEMENTED WHEN THE PIR GOES HIGH! THEY DON'T WORK EVEN IF YOU COMMENT OUT ALL THE PIR STUFF AND SIMPLY SAY, "WHEN IT IS DARK MAKE THE SERVO DO THIS!"

SAMPLE CODE TAKEN FROM ARDUINO REF LIBRARY.

Example Code

Sets pin 13 to the same value as pin 7, declared as an input.

int ledPin = 13;  // LED connected to digital pin 13
int inPin = 7;    // pushbutton connected to digital pin 7
int val = 0;      // variable to store the read value

void setup() {
  pinMode(ledPin, OUTPUT);  // sets the digital pin 13 as output
  pinMode(inPin, INPUT);    // sets the digital pin 7 as input
}

void loop() {
  val = digitalRead(inPin);   // read the input pin
  digitalWrite(ledPin, val);  // sets the LED to the button's value
}

If you have posted your sketch with that corrected then I missed it. If not then please post your code as it is now along with a schematic of your project. Preferably not a Fritzing picture. A photo of a hand drawn circuit is good enough

I will gladly do that tomorrow morning. I'm headed out to go fishing. Won't be back until the late AM hours. I draw really good too, BTW. ( mechanical draftsman, OLD SCHOOL, like they did 50 years ago, on a table) LOL, See you in the morning. Have a GREAT evening.

Good morning, Here is my current program with the servo portion in the loop commented out. So far, except for the servo part, everything works as anticipated. Attached you should find a schematic and the current code being used. As previously stated the servo code runs fine if it is uploaded to the uno, it is a relatively simple sketch and it does exactly what it is told to do. Note: Even if I comment out the PIR instructions, and put the servo routine in all by itself, absolutely NOTHING happens.

// ATtiny85 torch detector
// Author: Nick Gammon
// Date: 25 February 2015

// ATMEL ATTINY 25/45/85 / ARDUINO
// Pin 1 is /RESET
//
//                  +-\/-+
// Ain0 (D 5) PB5  1|    |8  Vcc
// Ain3 (D 3) PB3  2|    |7  PB2 (D 2) Ain1
// Ain2 (D 4) PB4  3|    |6  PB1 (D 1) pwm1
//            GND  4|    |5  PB0 (D 0) pwm0
//                  +----+

/*

  Pin 2 (PB3) <-- LDR (GL5539) --> Pin 7 (PB2) <----> 56 k <----> Gnd

  Pin 5 (PB0) <---- LED ---> 100 R <-----> Gnd

*/


#include <avr/sleep.h>    // Sleep Modes
#include <avr/power.h>    // Power management
#include <avr/wdt.h>      // Watchdog timer
#include <Servo.h>
Servo servo1;
int servoPin = 9;

const byte POWER_PIR = 7;          
const byte PIR_SIGNAL = 12;
int val = 0;
const byte LED = 13;
const byte LDR_ENABLE = 8;   
const byte LDR_READ = A0;     
const int LIGHT_THRESHOLD = 200;  // Flash LED when darker than this

// when ADC completed, take an interrupt
EMPTY_INTERRUPT (ADC_vect);

float getReading (byte port)       // Take an ADC reading in sleep mode (ADC)
{
  power_adc_enable() ;
  ADCSRA = bit (ADEN) | bit (ADIF);  // enable ADC, turn off any pending interrupt

  // set a2d prescale factor to 128
  // 8 MHz / 128 = 62.5 KHz, inside the desired 50-200 KHz range.

  ADCSRA |= bit (ADPS0) | bit (ADPS1) | bit (ADPS2);

  if (port >= A0)
    port -= A0;

#if defined(__AVR_ATmega328P__)

  ADMUX = bit (REFS0) | (port & 0x07); // AVcc

#endif

  noInterrupts ();
  set_sleep_mode (SLEEP_MODE_ADC);    // sleep during sample
  sleep_enable();

  // start the conversion
  ADCSRA |= bit (ADSC) | bit (ADIE);
  interrupts ();
  sleep_cpu ();
  sleep_disable ();

  // reading should be done, but better make sure
  // maybe the timer interrupt fired

  // ADSC is cleared when the conversion finishes
  while (bit_is_set (ADCSRA, ADSC))
  { }

  byte low  = ADCL;
  byte high = ADCH;

  ADCSRA = 0;  // disable ADC
  power_adc_disable();

  return (high << 8) | low;

}  // end of getReading

// watchdog interrupt
ISR (WDT_vect)
{
  wdt_disable();  // disable watchdog
}  // end of WDT_vect

#if defined(__AVR_ATmega328P__)                                
#define watchdogRegister WDTCSR
//#else
// #define watchdogRegister WDTCSR
#endif

void setup ()
{
  wdt_reset();
  pinMode (POWER_PIR, OUTPUT);
  pinMode (LED, OUTPUT);
  servo1.attach(servoPin);
  pinMode (LDR_ENABLE, OUTPUT);
  pinMode (PIR_SIGNAL, INPUT);
  ADCSRA = 0;            // turn off ADC
  power_all_disable ();  // power off ADC, Timer 0 and 1, serial interface
}  // end of setup

void loop ()
{
  // power up the LDR, take a reading
  digitalWrite (LDR_ENABLE, HIGH);

  int value = getReading (LDR_READ);
  // power off the LDR
  digitalWrite (LDR_ENABLE, LOW);

  if (value < LIGHT_THRESHOLD)    // if it's dark, do stuff
  {
    power_timer0_enable ();
    delay (1);  // let timer reach a known point

   digitalWrite (POWER_PIR, HIGH);
  }    else
    digitalWrite (POWER_PIR, LOW);

   { val = digitalRead (PIR_SIGNAL);   // read the input pin
  digitalWrite (LED,val);  // sets the LED to the PIR's value
  
/* NOTE: The servo must run at the same time the LED is on  
 
  
  servo1.write(0);   //degrees
  delay(50);         // delay between moves
  servo1.write(10);
  delay(50);
  servo1.write(0);
  delay(50);
  servo1.write(10);
  delay(50);*/
  
}
   
  {
    power_timer0_disable ();
  }

  goToSleep ();
}  // end of loop

void goToSleep ()
{
  set_sleep_mode (SLEEP_MODE_PWR_DOWN);
  noInterrupts ();       // timed sequence coming up

  // pat the dog
  wdt_reset();

  // clear various "reset" flags
  MCUSR = 0;
  // allow changes, disable reset, clear existing interrupt
  watchdogRegister = bit (WDCE) | bit (WDE) | bit (WDIF);
  // set interrupt mode and an interval (WDE must be changed from 1 to 0 here)
  watchdogRegister = bit (WDIE) | bit (WDP2) | bit (WDP1) | bit (WDP0);    // set WDIE, and 2 seconds delay

  sleep_enable ();       // ready to sleep
  interrupts ();         // interrupts are required now
  sleep_cpu ();          // sleep
  sleep_disable ();      // precaution
}  // end of goToSleep

Since you might ask here is a working servo sketch, a short version. It works fine.

#include <Servo.h>
Servo servo1;
int servoPin = 9;

void setup(){
  
  servo1.attach(servoPin);
}

void loop(){
  
  servo1.write(0);
  delay(50);
  servo1.write(10);
  delay(50);
  servo1.write(0);
  delay(50);
  servo1.write(10);
  delay(50);
  
}

I have lost track of what is working and what isn't

Does the built in LED on the Uno show the state of the PIR correctly ?

I note that despite the comment in this line of code

        /* NOTE: The servo must run at the same time the LED is on

there is no check on the state of the PIR or the LED to meet the stated condition

it means if it is dark the PIR turns on and reads the val which yes it all works

The problem is getting the servo to run at the same time the LED is turned on by the PIR Actually the problem is getting the servo to run at all.

It could be I'm using the wrong send servo signal pin JUST DOUBLE CHECKED 9 IS A PWM PIN
a conflict in timers
a conflict in libraries
COULD IT BE A HZ ISSUE

I know there's no condition written for the servo to work when the PIR goes high. But as stated, if you take the PIR and LED OUT of the equation, the servo still doesn't work.

The Servo library does not require that the pin used for the servo is PWM enabled

I suggest that you start by writing a sketch that makes the servo oscillate when an input is taken HIGH using a pushbutton or just a jumper to 5V. Once that works add the PIR code but not the LDR code and sleep, power and wdt code. Once that works add back the LDR code. Continue that way until either the sketch works as you want or you encounter a problem

This is where we run into a problem. i don't have a button so I am using the HIGH from the PIR. The second line of the loop, compile it, it's short and please explain what the error means so I can figure out how to fix it. I would greatly appreciate that.

#include <Servo.h>
Servo servo1;
int servoPin = 9;
const byte POWER_PIR = 7;          
const byte PIR_SIGNAL = 12;
int val = 0;

void setup(){
  pinMode (POWER_PIR, OUTPUT);
  servo1.attach(servoPin);
  pinMode (PIR_SIGNAL, INPUT);
}

void loop(){
  val = digitalRead (PIR_SIGNAL);   // read the input pin
 analogWrite (servo1,val);  // sets the LED, or SERVO to the PIR's value**
  
  servo1.write(0);
  delay(50);
  servo1.write(10);
  delay(50);
  servo1.write(0);
  delay(50);
  servo1.write(10);
  delay(50);
}

Hence what I suggested

Compilation error: cannot convert 'Servo' to 'uint8_t {aka unsigned char}' for argument '1' to 'void analogWrite(uint8_t, int)'

The error is telling you that the analogWrite() function expects a byte value (ie a pin number) as its first argument, not a servo object in this line of code

    analogWrite(servo1, val);       // sets the LED, or SERVO to the PIR's value**

In any case, you cannot control a servo using analogWrite()