Chris Gilbert's E.A.T. Blog
Friday, December 17, 2010
Thursday, December 16, 2010
Project Code
#include <Servo.h>
#define CLOSED 11
#define ALARM 13
int but = 0;
const int analogPin = 0;
const int ledCount = 8;
int ledPins[] = {
2,3,4,5,6,7,8,9
};
Servo myservo;
int val = 0;
int sensorReading = 0;
#define soundalarm 10
//FUNCTIONS
void setup(){
for (int thisLed = 0; thisLed < ledCount; thisLed++){
pinMode(ledPins[thisLed], OUTPUT);
}
pinMode(CLOSED, INPUT);
pinMode(ALARM, INPUT);
pinMode(soundalarm, OUTPUT);
myservo.attach(12);
myservo.write(val);
}
void senRead(){
int sensorReading = analogRead(analogPin);
if (sensorReading < 550){
senRead();
}
else{
int ledLevel = map(sensorReading, 500, 1023, 0, ledCount);
for (int thisLed = 0; thisLed < ledCount; thisLed++){
if (thisLed < ledLevel){
digitalWrite(ledPins[thisLed], HIGH);
}
else {
digitalWrite(ledPins[thisLed], LOW);
}
}
}
if (sensorReading >= 975){
senRead();
}
delay(1000);
}
void openDoor(){
val = 1500;
myservo.write(val);
delay(1000);
}
void alarm(){
int a = digitalRead(ALARM);
if (a == HIGH){
delay(1000);
alarm2();
}
else{
alarm();
}
}
void alarm2(){
int but = digitalRead(CLOSED);
int a = digitalRead(ALARM);
if (a == HIGH){
digitalWrite(soundalarm, HIGH);
delay(5000);
digitalWrite(soundalarm, LOW);
alarm2();
}
else{
if (but == HIGH){
val = 0;
myservo.write(val);
delay(1000);
clearleds();
}
else{
alarm2();
}
}
}
void clearleds(){
for (int thisLed = 0; thisLed < ledCount; thisLed++){
digitalWrite(ledPins[thisLed], LOW);
}
}
//MAIN LOOP
void loop(){
senRead();
openDoor();
alarm();
}
#define CLOSED 11
#define ALARM 13
int but = 0;
const int analogPin = 0;
const int ledCount = 8;
int ledPins[] = {
2,3,4,5,6,7,8,9
};
Servo myservo;
int val = 0;
int sensorReading = 0;
#define soundalarm 10
//FUNCTIONS
void setup(){
for (int thisLed = 0; thisLed < ledCount; thisLed++){
pinMode(ledPins[thisLed], OUTPUT);
}
pinMode(CLOSED, INPUT);
pinMode(ALARM, INPUT);
pinMode(soundalarm, OUTPUT);
myservo.attach(12);
myservo.write(val);
}
void senRead(){
int sensorReading = analogRead(analogPin);
if (sensorReading < 550){
senRead();
}
else{
int ledLevel = map(sensorReading, 500, 1023, 0, ledCount);
for (int thisLed = 0; thisLed < ledCount; thisLed++){
if (thisLed < ledLevel){
digitalWrite(ledPins[thisLed], HIGH);
}
else {
digitalWrite(ledPins[thisLed], LOW);
}
}
}
if (sensorReading >= 975){
senRead();
}
delay(1000);
}
void openDoor(){
val = 1500;
myservo.write(val);
delay(1000);
}
void alarm(){
int a = digitalRead(ALARM);
if (a == HIGH){
delay(1000);
alarm2();
}
else{
alarm();
}
}
void alarm2(){
int but = digitalRead(CLOSED);
int a = digitalRead(ALARM);
if (a == HIGH){
digitalWrite(soundalarm, HIGH);
delay(5000);
digitalWrite(soundalarm, LOW);
alarm2();
}
else{
if (but == HIGH){
val = 0;
myservo.write(val);
delay(1000);
clearleds();
}
else{
alarm2();
}
}
}
void clearleds(){
for (int thisLed = 0; thisLed < ledCount; thisLed++){
digitalWrite(ledPins[thisLed], LOW);
}
}
//MAIN LOOP
void loop(){
senRead();
openDoor();
alarm();
}
Project 3 - Parts/Product
Inspirational/Helpful Sites
Monday, November 22, 2010
Project 2 - Construction Video
Below is just a quick view around our whole housing for the shot dispenser to give you a look around the entire unit before being a finished piece.
Subscribe to:
Posts (Atom)