Hi! I’m working with on an IR Controlled Servo project. The code runs fine on the Arduino UNO, but I’m trying to shrink my project using an ATtiny85 and the Arduino UNO as ISP, but it says , “Serial” was not declared in this scope. I want to keep the Serial references on my code. Can anyone please help me?
this is the code:
// This code is for controlling servo motor with IR remote control
// When clicking at any of two buttons the motor is toggling between the rotation and stop
#include <IRremote.h> //must copy IRremote library to arduino libraries
#include <Servo.h>
#define plus 0x925D5B5D //clockwise rotation button
#define minus 0xCB3D6F7D //counter clockwise rotation button
#define BUTTON_1 0x6BFD8B01 //Moves servo to 0 degrees
#define BUTTON_2 0x42640C99 //Moves servo to 90 degrees
#define BUTTON_3 0xB1EFBA9D //Moves servo to 180 degrees
const int greenLed = 1;
const int redLed = 2;
int RECV_PIN = 0; //IR receiver pin
Servo servo;
int val; //rotation angle
int16_t pos; // variable to store the servo position
int16_t speed; // Number of degrees to move each time a left/right button is pressed
//bool cwRotation, ccwRotation; //the states of rotation
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600); I REPLACED THIS TEMPORARILY FOR THE NEW CODE
pos = 90; // start at midpoint 90 degrees
speed = 3; // servo moves 3 degrees each time left/right is pushed
servo.write(pos); // Set initial position
irrecv.enableIRIn(); // Start the receiver
pinMode(greenLed, OUTPUT);
pinMode(redLed, OUTPUT);
}
void loop()
{
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX); // TEMP REMOVED FOR NEW CODE
irrecv.resume(); // Receive the next value
switch(results.value) {
case BUTTON_1: pos=0*90;
digitalWrite(greenLed, HIGH);
digitalWrite(redLed, LOW);
Serial.println(“Gate Unlocked”); break;
case BUTTON_2: pos=1*90;
digitalWrite(greenLed, LOW);
digitalWrite(redLed, LOW);
Serial.println(“Middle Ground”);break;
case BUTTON_3: pos=2*90;
digitalWrite(greenLed, LOW);
digitalWrite(redLed, HIGH);
Serial.println(“Gate Locked”);break;
}
}
servo.write(pos); // tell servo to go to position in variable ‘pos’
delay(20); //General speed
}