CodeDump
Add
Browse
Sign up
Sign in
Select language
ActionScript
Ajax
Android
AngularJS
Apache Configuration
AppleScript
ASP.NET (C#)
AutoHotkey
Bash
Brainfuck
C
C#
C++
CoffeeScript
CSS
CSS Extras
Dart
Eiffel
Erlang
F#
Fortran
Gherkin
Git
Go
Groovy
Haml
Handlebars
Haskell
HTML
HTTP
Ini
iOS
Jade
Java
Javascript
jQuery
JSON
Julia
Keyman
LaTeX
Linux
Less
LOLCODE
Makefile
Markdown
MATLAB
MySQL
NASM
Node.js
NSIS
Objective-C
Pascal
Perl
PHP
PHP Extras
PowerShell
Python
R
React JSX
reST (reStructuredText)
Rip
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Stylus
Swift
Twig
TypeScript
Vb.net
VHDL
Wiki markup
YAML
Other
Search
You're not signedin! You can't edit or track the code you're going to add. If you want to maintain and track your code, you need to
signin
or
signup
.
We improved our code engine! From now on you can add more then just one peace of code! Use the "
Add more code
" button to add more code".
Add Codedump
Description (Markdown supported)
Title or filename
Language
Choose language
ActionScript
Ajax
Android
AngularJS
Apache Configuration
AppleScript
ASP.NET (C#)
AutoHotkey
Bash
Brainfuck
C
C#
C++
CoffeeScript
CSS
CSS Extras
Dart
Eiffel
Erlang
F#
Fortran
Gherkin
Git
Go
Groovy
Haml
Handlebars
Haskell
HTML
HTTP
Ini
iOS
Jade
Java
Javascript
jQuery
JSON
Julia
Keyman
LaTeX
Linux
Less
LOLCODE
Makefile
Markdown
MATLAB
MySQL
NASM
Node.js
NSIS
Objective-C
Pascal
Perl
PHP
PHP Extras
PowerShell
Python
R
React JSX
reST (reStructuredText)
Rip
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Stylus
Swift
Twig
TypeScript
Vb.net
VHDL
Wiki markup
YAML
Other
Code
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib #include <Wire.h> #include "RTClib.h" #define ledPin 9; RTC_DS1307 rtc; DateTime timeNow; char daysOfTheWeek[7][12] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Sunday", "Saturday"}; void setup () { Serial.begin(57600); if (! rtc.begin()) { Serial.println("Couldn't find RTC"); while (1); } if (! rtc.isrunning()) { Serial.println("RTC is NOT running!"); // following line sets the RTC to the date & time this sketch was compiled rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // This line sets the RTC with an explicit date & time, for example to set // January 21, 2014 at 3am you would call: // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0)); } } void printTimeToSerial(){ Serial.print(timeNow.year(), DEC); Serial.print('/'); Serial.print(timeNow.month(), DEC); Serial.print('/'); Serial.print(timeNow.day(), DEC); Serial.print(" ("); Serial.print(daysOfTheWeek[timeNow.dayOfTheWeek()]); Serial.print(") "); Serial.print(timeNow.hour(), DEC); Serial.print(':'); Serial.print(timeNow.minute(), DEC); Serial.print(':'); Serial.print(timeNow.second(), DEC); Serial.println(); } // 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 <<-- This is the hours int fadeValueSetpoint[24] = {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 127, 127, 127, 127, 127, 127, 127}; //<<-- This is the fade value limit for the respective hour void loop () { static boolean fadeComplete = false; //static means this variable will not be destroyed at the end of the loop and be used in the next scan cycle within this function static int timeHr = 0; static long printDelay = 0; static long fadeDelay = 0; timeNow = rtc.now(); if (millis() > printDelay) { //this is a passive delay to send the time to the serial port, but does not pause the program printTimeToSerial(); printDelay = millis() + 3000; } timeHr = timeNow.hour(); //this is used to select the fade value limit if (millis() > printDelay) { //this will constantly update to the setpoint you give for a given hour. It will close in on it's setpoint every 500ms if (fadeValue) > (fadeValueSetPoint[timeHr] + 5)) fadeValue -= 5; if (fadeValue) < (fadeValueSetPoint[timeHr] - 5)) fadeValue += 5; analogWrite(ledPin, fadeValue); printDelay = millis() + 500; //to change fade timebase, change the 500 to the ms you want. } }
Access
Everyone
Just me
Create