// // Copyright 2014, Aaron Ardiri // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // simple arduino sketch using six LED's and the piezo element // // - design is to implement an LED binary counter (0..59 seconds) #define ledPINBase 2 #define ledPINCount 6 // pins 2,3,4,5,6 and 7 #define piezoPIN 8 // we want to count seconds #define delayPeriod 1000 #define sec_in_min 60 // we want to play tones an octive up and down from middle C #define toneBase 440 #define toneDuration 25 // some global variables int counter = 0; // configuration of the arduino void setup() { // configure the LED pins - turn them all off for (int i=ledPINBase; i<(ledPINBase+ledPINCount); i++) { pinMode(i, OUTPUT); digitalWrite(i, LOW); } } // called periodically by the arduino core - this is where we do stuff void loop() { int b, led; counter++; if (counter == sec_in_min) counter = 0; // turn on/off bits as appropriate for the binary representation b = 0x20; // 00100000b led = ledPINBase; while (b != 0) { // depending if the bit is set; turn on/off an LED if (counter & b) digitalWrite(led, HIGH); else digitalWrite(led, LOW); // move to the next bit, LED b = b >> 1; led++; } // play a ticking sound, or when a minute is reached - longer tone if (counter == 0) tone(piezoPIN, toneBase * 5, toneDuration * 20); else tone(piezoPIN, toneBase, toneDuration); // wait a specific period of time before the next iteration delay(delayPeriod); }