Last active
March 7, 2020 22:14
-
-
Save mattrude/852ef192b62eae4dcf02f6cc7b712212 to your computer and use it in GitHub Desktop.
ATtiny85 Traffic Stop Light - Written with the Atmel Studio 7 - This program turns on (in order) the Red LED, waits for 5 seconds, then turns on the Green LED, waits for 5 seconds, then turns on the Yellow LED, waits for 2.5 seconds and repeats cycle.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ATtiny85 Traffic Stop Light - Version 0.2.0 - 2020-03-07 | |
* Copyright (c) 2020 Matt Rude <[email protected]> | |
* | |
* ********************************************************************************* | |
* | |
* This is a simple Traffic Stop Light program written for an ATtiny85 using | |
* Atmel Studio 7: https://www.microchip.com/mplab/avr-support/atmel-studio-7 | |
* | |
* For more on the ATtiny85, see: https://www.microchip.com/wwwproducts/en/ATtiny85 | |
* | |
* The program turns on (in order) the Red LED, waits for 5 seconds, then turns on | |
* the Green LED, waits for 5 seconds, then turns on the Yellow LED, waits for 2.5 | |
* seconds and repeats cycle. | |
* | |
* The ATtiny85 was programed with the external programmer, and is running is at a | |
* clock speed of 1MHz (internal). | |
* | |
* The circuit is powered by an external DC buck converter running at 3.3v. | |
* | |
* ********************************************************************************* | |
* | |
* Required Hardware: | |
* | |
* - 1x 1330 ATtiny85-20pu | |
* - 1x Red LED | |
* - 1x Yellow LED | |
* - 1x Green LED | |
* - 1x 220ohm Resistor | |
* - 1x Breadboard | |
* - 8x Jumper Wires | |
* | |
* Simplified ATtiny85 pin out: | |
* (Note: the dot next to the Reset pin, represents the dot on the chip.) | |
* ______ | |
* Reset - PB5 - |. | - VCC - 5v+ | |
* A3 - PB3 - | | - PB2 - A1 | |
* A2 - PB4 - | | - PB1 - PWM | |
* GND - |______| - PB0 - PWM | |
* | |
* | |
* ********************************************************************************* | |
* | |
* Changelog: | |
* | |
* 2020-03-07 - 0.2.0 - Convert to use Atmel Studio 7 opposed to Arduino IDE | |
* 2020-02-15 - 0.1.2 - Change program to boot with the Red light first. | |
* - Change Red & Green delay to 5 seconds, and Yellow to 2.5. | |
* 2020-02-02 - 0.1.1 - Correct minor spelling and white space cleanup. | |
* 2020-01-30 - 0.1.0 - Initial Release. | |
* | |
* | |
* ********************************************************************************* | |
* | |
* MIT License | |
* | |
* Copyright (c) 2020 Matt Rude <[email protected]> | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy | |
* of this software and associated documentation files (the "Software"), to deal | |
* in the Software without restriction, including without limitation the rights | |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
* copies of the Software, and to permit persons to whom the Software is | |
* furnished to do so, subject to the following conditions: | |
* | |
* The above copyright notice and this permission notice shall be included in all | |
* copies or substantial portions of the Software. | |
* | |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
* SOFTWARE. | |
* | |
* ********************************************************************************* | |
*/ | |
#define F_CPU 1000000UL // Set the CPU clock frequency to 1MHz | |
// Add the required libraries to the project | |
#include <util/delay.h> // The delay.h library is used to pause the program | |
#include <avr/io.h> // The io.h library is used to communicate with pins | |
// Define the pins used and how they are used | |
#define redLed PB0 // Set pin 0 as the Red pin | |
#define yellowLed PB1 // Set pin 1 as the Yellow pin | |
#define greenLed PB2 // Set pin 2 as the Green pin | |
// Starting the main loop | |
int main(void) { | |
// Initialize the digital pins as Outputs. | |
DDRB |= (1<<PB0); // Setting Red LED as output | |
DDRB |= (1<<PB1); // Setting Yellow LED as output | |
DDRB |= (1<<PB2); // Setting Green LED as output | |
// Start the primary loop | |
while (1) { | |
PORTB |= (1<<redLed); // Turn the Red LED on. | |
_delay_ms(5000); // Wait for 5 seconds. | |
PORTB &= ~(1<<redLed); // Turn the Red LED off. | |
PORTB |= (1<<greenLed); // Turn the Green LED on. | |
_delay_ms(5000); // Wait for 5 seconds. | |
PORTB &= ~(1<<greenLed); // Turn the Green LED off. | |
PORTB |= (1<<yellowLed); // Turn the Yellow LED on. | |
_delay_ms(2500); // Wait for 2.5 seconds. | |
PORTB &= ~(1<<yellowLed); // Turn the Yellow LED off. | |
} // Ending the primary loop | |
} // Ending main main loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment