I am using the Arduino UNO as a programmer to program the ATtiny85 , but upon pressing the upload button the error message avrdude: stk500_getsync(): not in sync: resp=0x00 appears.
Here is my code:
//pin definitions
#define pingPin 3
#define buzzerPin 0
//constant definitions
#define DELAY_BEFORE_INITIAL 5000
#define ALARM_DISTANCE 35
#define BUZZER_FREQ 500
//variables
#include <Arduino.h>
#include <WProgram.h>
boolean alarm = false;
long currentDistance;
const int buttonPin1 = 4;
const int buttonPin2 = 2;
const int buttonPin3 = 1;
int buttonState;
int lastButtonState = LOW;
long lastDebounceTime = 0;
long debounceDelay = 50;
void setup() {
//setup pins
pinMode(buttonPin1,INPUT);
pinMode(buttonPin2,INPUT);
pinMode(buttonPin3,INPUT);
pinMode(buzzerPin,OUTPUT);
//delay before beginning loop
delay(DELAY_BEFORE_INITIAL);
}
void loop()
{
pinMode(pingPin, OUTPUT);
if(!alarm)
{
//check distance
long duration, distance;
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(10);
pinMode(pingPin,INPUT);
digitalWrite(pingPin, LOW);
duration = pulseIn(pingPin, HIGH);
distance = (duration/2) / 29.1;
//if distance is greater than ALARM_DISTANCE begin alarm
if(distance>=ALARM_DISTANCE)
alarm=true;
}
else{
delay(BUZZER_FREQ);
digitalWrite(buzzerPin, HIGH);
delay(BUZZER_FREQ);
digitalWrite(buzzerPin,LOW);
}
}