#include <avr/power.h>
#include <avr/sleep.h>
int enablePin = 11;
int in1Pin = 10;
int in2Pin = 9;
int switchPin = 7;
int lightPin = 0;
int baselevel;
int lightlevel;
int sleepStatus = 0;
int count = 0;
void setup()
{
baselevel = analogRead(lightPin);
pinMode(in1Pin, OUTPUT);
pinMode(in2Pin, OUTPUT);
pinMode(enablePin, OUTPUT);
pinMode(switchPin, INPUT);
Serial.begin(9600);
}
void switchPinInterrupt (void)
{detachInterrupt(0);
}
void sleepNow(void)
{
attachInterrupt (0,switchPinInterrupt,LOW);
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
}
void loop()
{
count++;
delay(1000);
lightlevel = analogRead(lightPin);
if ((lightlevel + 100) < baselevel)
{int speed = 0;
}
else
{ int speed = analogRead(lightPin) / 4;}
if (count >= 60)
{count = 0;
delay(100);
sleepNow();
}
}
Sleep/Wake function
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- asmith1265
- Posts: 1
- Joined: Mon Dec 01, 2014 12:31 pm
Sleep/Wake function
I need to code a DC motor to run at a certain speed according to the light. The motor must stop if there is no light. Also I want to set the robot to sleep after 60 seconds and be awoken by a switch. Here is the code I have as of right now the motor isn't even running. I'm sure my wiring is set up right, can anybody please help?
- adafruit_support_bill
- Posts: 88096
- Joined: Sat Feb 07, 2009 10:11 am
Re: Sleep/Wake function
What are you using to drive the motor? I don't see any code for that.the motor isn't even running
Code: Select all
{int speed = 0;
}
else
{ int speed = analogRead(lightPin) / 4;}
Please be positive and constructive with your questions and comments.