Skip to content

Commit

Permalink
math
Browse files Browse the repository at this point in the history
  • Loading branch information
chee committed Oct 7, 2019
0 parents commit baef183
Show file tree
Hide file tree
Showing 79 changed files with 15,733 additions and 0 deletions.
80 changes: 80 additions & 0 deletions 7seggers/7seggers.ino
@@ -0,0 +1,80 @@
const byte pin_a = 11;
const byte pin_b = 10;
const byte pin_c = 9;
const byte pin_d = 7;
const byte pin_e = 6;
const byte pin_f = 12;
const byte pin_g = 13;
const byte pin_p = 8;

const byte top = 1;
const byte top_right = 2;
const byte bottom_right = 4;
const byte bottom = 8;
const byte bottom_left = 16;
const byte top_left = 32;
const byte middle = 64;

const byte segments[] = {top, top_right, bottom_right, bottom, bottom_left, top_left, middle};
const byte pins[] = {pin_a, pin_b, pin_c, pin_d, pin_e, pin_f, pin_g, pin_p};

const byte ZERO = top | top_right | bottom_right | bottom | bottom_left | top_left;
const byte ONE = top_right | bottom_right;
const byte TWO = top | top_right | bottom | bottom_left | middle;
const byte THREE = top | top_right | bottom_right | bottom | middle;
const byte FOUR = top_right | bottom_right | top_left | middle;
const byte FIVE = top | bottom_right | bottom | top_left | middle;
const byte SIX = top | bottom_right | bottom | bottom_left | top_left | middle;
const byte SEVEN = top | top_right | bottom_right;
const byte EIGHT = top | top_right | bottom_right | bottom | bottom_left | top_left | middle;
const byte NINE = top | top_right | bottom_right | top_left | middle;
const byte A = bottom_left | top_left | top | middle | top_right | bottom_right;
const byte B = EIGHT;
const byte E = top | top_left | bottom_left | bottom | middle;
const byte H = top_right | bottom_right | bottom_left | top_left | middle;
const byte I = ONE;

void setup() {
for (byte i = 0; i < 7; i = i + 1) {
pinMode(pins[i], OUTPUT);
}
}

void loop() {
byte sequence_length = 12;
byte sequence[sequence_length] = {
NINE,
EIGHT,
SEVEN,
SIX,
FIVE,
FOUR,
THREE,
TWO,
ONE,
ZERO,
0
};

for (byte n = 0; n < sequence_length; n = n + 1) {
byte number = sequence[n];
for (byte i = 0; i < 7; i++) {
digitalWrite(pins[i], (number & segments[i]) ? LOW : HIGH);
}
delay(100);
}


digitalWrite(pin, segment_top);

byte abe_length = 6;
byte abe[abe_length] = {H, I, 0, A, B, E};

for (byte n = 0; n < abe_length; n = n + 1) {
byte number = abe[n];
for (byte i = 0; i < 7; i = i + 1) {
digitalWrite(pins[i], (number & segments[i]) ? LOW : HIGH);
}
delay(1000);
}
}
7 changes: 7 additions & 0 deletions libraries/Arduino_Learning_Board/README.md
@@ -0,0 +1,7 @@
# ArduinoLearningBoard-Lib
Arduino Learning Board Library and Examples (for Arduino IDE)

Created for the Arduino Learning Board project and edited to
be able to be included in the Arduino IDE Library Manager

Visit http://www.ArduinoLearningBoard.com for more info
23 changes: 23 additions & 0 deletions libraries/Arduino_Learning_Board/examples/ALB_Blink/ALB_Blink.ino
@@ -0,0 +1,23 @@
/*
* Arduino Learning Board Project - Simple LED Blink Example
*
* ALB_Blink - This very simple sketch demonstrates how to configure D13
* as an output and blink the on-board LED. There is an LED on the Arduino
* Nano connected to D13 that we can control with our code
*
* Please visit http://www.ArduinoLearningBoard.com for more information
*
* Last modified July 2016 by Jeff Shapiro <Jeff@ArduinoLearningBoard.com>
*/
void setup()
{
pinMode(13, OUTPUT); // Set Digital Pin 13 as an Output
}

void loop()
{
digitalWrite(13, HIGH); // Turn the LED ON
delay(500); // delay (do nothing) for 500ms (1/2 of a second)
digitalWrite(13, LOW); // Turn the LED OFF
delay(500); // delay (do nothing) for 500ms (1/2 of a second)
}
@@ -0,0 +1,65 @@
/*
* Arduino Learning Board Project - Reading a Learning Board Button
*
* ALB_Button - This relatively simple sketch demonstrates how to configure D12
* as an Input to read a button. It also configures D13 as an output to blink
* both the on-board LED and an LED hooked to D13 in response to the button
* being pressed.
*
* Please visit http://www.ArduinoLearningBoard.com for more information
*
* Last modified August 2016 by Jeff Shapiro <Jeff@ArduinoLearningBoard.com>
*/

// Learning Board LED is connected to D13 and Ground
// Learning Board Button is connected to D12 and Ground

int blink = true; // Should we be blinking, start with Yes
int ledState = LOW; // ledState used to set the current state of the LED
unsigned long previousMillis = 0; // Hold the last time the LED was updated

void setup()
{
pinMode(12, INPUT_PULLUP); // Set Digital Pin 12 as an Input with a Pullup to 5V
pinMode(13, OUTPUT); // Set Digital Pin 13 as an Output
}

void loop()
{
// See if button is being pushed
// BUtton UN-Pushed returns high (pull-up)
// Button PUSHED returns LOW (switch connects D12 to Ground)
// Notice the double == in the line below
// - a single = sets the two sides equal (not what we want)
// - a double == Compares the two sides
if (digitalRead(12) == LOW)
{
// Button is pressed, wait until it's released
while (digitalRead(12) == LOW)
; // Do nothing while we wait
blink = !blink; // Reverse the value of blink (if it was true, make it false, and vice-versa)
ledState = LOW;
digitalWrite(13, ledState);
delay(200); // Delay for 200ms to ignore any "bounce" in the switch
}

if (blink)
{
if (millis() - previousMillis >= 500)
{
previousMillis = millis(); // Store the last time you blinked the LED

// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
{
ledState = HIGH;
}
else
{
ledState = LOW;
}

digitalWrite(13, ledState);
}
}
}
@@ -0,0 +1,36 @@
/*
* Arduino Learning Board Project - Passive Buzzer Example
*
* This example uses the tone function to create a siren
* sound on the passive buzzer. It starts with a low frequency and
* increases to a higher frequency, then back down again and repeats
*
* Please visit http://www.ArduinoLearningBoard.com for more information
*
* Last modified July 2016 by Jeff Shapiro <Jeff@ArduinoLearningBoard.com>
*/

int buzzer_pin = 3; // What pin is the buzzer connected to
int i = 0;

void setup()
{
pinMode(buzzer_pin, OUTPUT); // Configure the buzzer pin as an output pin
}

void loop()
{
// Play low to high frequencies
for(i = 25; i < 120; i++)
{
tone(buzzer_pin, 20 * i, 200); // Create a tone/note from 500 to 2400 Hz
delay(20);
}

// Now play high to low frequencies
for(i = 120; i >= 25; i--)
{
tone (buzzer_pin, 20 * i, 200); // Create a tone/note from 2400 Hz to 500 hz
delay(20);
}
}
@@ -0,0 +1,128 @@
/*
* Arduino Learning Board Project - HC-SR04 Ultrasonic Sensor Example
*
* Please visit http://www.ArduinoLearningBoard.com for more information
*
* Last modified August 2016 by Jeff Shapiro <Jeff@ArduinoLearningBoard.com>
*/

// First DEFINE the components of the library we're going to use for this sketch
// Define #USE_ALB_DS1302 to include the DS1302 functions of the ArduinoLearningBoard Library
// (Must do this before including ArduinoLearningBoard.h)

#define USE_ALB_DS1302

// NOW include the main ArduinoLearningBoard library (quotes now, <Arduino...> when it's "live")
// Based on the defines above, the appropriate code will be added to the project
#include "ArduinoLearningBoard.h"

// VCC -> 5V
// GND -> GND
// CLK -> D11
// DAT -> D10
// RST -> D9

// Set pins: CE, IO,CLK
DS1302RTC RTC(9, 10, 11);

void setup()
{
Serial.begin(9600); // Start Serial port so we can see the results

Serial.println("DS1302RTC Read Test");
Serial.println("-------------------");

Serial.println("RTC module activated");
Serial.println();
delay(500);

if (RTC.haltRTC())
{
Serial.println("The DS1302 is stopped. Set the time as shown");
Serial.println("below to initialize the clock and begin running.");
Serial.println();
}

Serial.println("To set the time, send a string in the following format:");
Serial.println("yy,m,d,h,m,s {Year, Month, Day, Hour, Minute, Second}");
Serial.println("i.e. 16,9,1,11,30,00 would set the time to September 1, 2016 at 11:30:00 AM");
delay(3000);
}

void loop()
{
tmElements_t tm;
time_t t;

//check for input to set the RTC, minimum length is 12, i.e. yy,m,d,h,m,s
if (Serial.available() >= 12)
{
//note that the tmElements_t Year member is an offset from 1970,
//but the RTC wants the last two digits of the calendar year.
//use the convenience macros from Time.h to do the conversions.
int y = Serial.parseInt();
if (y >= 100 && y < 1000)
Serial.println("Error: Year must be two digits or four digits!");
else
{
if (y >= 1000)
tm.Year = CalendarYrToTm(y);
else //(y < 100)
tm.Year = y2kYearToTm(y);
tm.Month = Serial.parseInt();
tm.Day = Serial.parseInt();
tm.Hour = Serial.parseInt();
tm.Minute = Serial.parseInt();
tm.Second = Serial.parseInt();
t = makeTime(tm);
//use the time_t value to ensure correct weekday is set
if(RTC.set(t) == 0) // Success
{
setTime(t);
Serial.println("RTC set.");
}
else
Serial.println("RTC set failed!");
//dump any extraneous input
while (Serial.available() > 0) Serial.read();
}
}

Serial.print("UNIX Time: ");
Serial.print(RTC.get());

if (! RTC.read(tm))
{
Serial.print(" Time = ");
print2digits(tm.Hour);
Serial.write(':');
print2digits(tm.Minute);
Serial.write(':');
print2digits(tm.Second);
Serial.print(", Date (D/M/Y) = ");
Serial.print(tm.Day);
Serial.write('/');
Serial.print(tm.Month);
Serial.write('/');
Serial.print(tmYearToCalendar(tm.Year));
Serial.print(", DoW = ");
Serial.print(tm.Wday);
Serial.println();
}
else
{
Serial.println("DS1302 read error! Please check the circuitry.");
Serial.println();
delay(9000);
}

// Wait one second before repeating :)
delay (1000);
}

void print2digits(int number)
{
if (number >= 0 && number < 10)
Serial.write('0');
Serial.print(number);
}
@@ -0,0 +1,30 @@
/*
* Arduino Learning Board Project - I2C Address Scanner Example
*
* Please visit http://www.ArduinoLearningBoard.com for more information
*
* Last modified July 2016 by Jeff Shapiro <Jeff@ArduinoLearningBoard.com>
*/

// First DEFINE the components of the library we're going to use for this sketch
// Define #USE_ALB_LCD_I2C to include the LCD functions of the ArduinoLearningBoard Library
// (Must do this before including ArduinoLearningBoard.h)
#define USE_ALB_I2C_Scan // LCD Library

// NOW include the main ArduinoLearningBoard library
// Based on the defines above, the appropriate modules will be added to the project
#include <ArduinoLearningBoard.h>

ALB_I2C_Scan i2c_scan;

void setup()
{
// Open serial port at 9600 baud for debugging
Serial.begin(9600);

i2c_scan.scan();
}

void loop()
{
}

0 comments on commit baef183

Please sign in to comment.