Skip to content

Commit

Permalink
Initial Draft of Library
Browse files Browse the repository at this point in the history
Draft of all library materials
  • Loading branch information
jrleeman committed Jun 13, 2020
1 parent 62fd3b6 commit ac05fca
Show file tree
Hide file tree
Showing 10 changed files with 549 additions and 0 deletions.
40 changes: 40 additions & 0 deletions examples/blink/blink.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* blink.ino
* Blink Example for Leeman Geophysical LLC Learning Shield
* Blinks all four LEDs on the learning shield - turning them
* on for one second and then off for one second.
*/

#include <lglearning.h>

// Runs once when the Arduino turns on
void setup()
{
// Set the pins to be outputs
pinMode(PIN_LED_BLUE, OUTPUT);
pinMode(PIN_LED_RED, OUTPUT);
pinMode(PIN_LED_YELLOW, OUTPUT);
pinMode(PIN_LED_GREEN, OUTPUT);
}

// This block of code repeats over and over
void loop()
{
// Turn the LEDs on
digitalWrite(PIN_LED_BLUE, HIGH);
digitalWrite(PIN_LED_RED, HIGH);
digitalWrite(PIN_LED_YELLOW, HIGH);
digitalWrite(PIN_LED_GREEN, HIGH);

// Wait for 1 second (1000 milliseconds)
delay(1000);

// Turn the LEDs off
digitalWrite(PIN_LED_BLUE, LOW);
digitalWrite(PIN_LED_RED, LOW);
digitalWrite(PIN_LED_YELLOW, LOW);
digitalWrite(PIN_LED_GREEN, LOW);

// Wait for 1 second (1000 milliseconds)
delay(1000);
}
36 changes: 36 additions & 0 deletions examples/buttons_leds/buttons_leds.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* buttons_leds.ino
* Turns on the light by a button when the button is pressed.
*/

#include <lglearning.h>

void setup()
{
// Make the LED pins outputs
pinMode(PIN_LED_BLUE, OUTPUT);
pinMode(PIN_LED_RED, OUTPUT);
pinMode(PIN_LED_YELLOW, OUTPUT);
pinMode(PIN_LED_GREEN, OUTPUT);

// Make the button pins inputs
pinMode(PIN_SWITCH_A, INPUT);
pinMode(PIN_SWITCH_B, INPUT);
pinMode(PIN_SWITCH_C, INPUT);
pinMode(PIN_SWITCH_D, INPUT);
}

void loop()
{
// Check switch A - make the state of the LED match!
digitalWrite(PIN_LED_GREEN, digitalRead(PIN_SWITCH_A));

// Check switch B - make the state of the LED match!
digitalWrite(PIN_LED_RED, digitalRead(PIN_SWITCH_B));

// Check switch C - make the state of the LED match!
digitalWrite(PIN_LED_BLUE, digitalRead(PIN_SWITCH_C));

// Check switch D - make the state of the LED match!
digitalWrite(PIN_LED_YELLOW, digitalRead(PIN_SWITCH_D));
}
18 changes: 18 additions & 0 deletions examples/knob_serial/knob_serial.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* knob_serial.ino
* Reads the potentiometer knob on the board and sends the
* reading out over the serial port.
*/

#include <lglearning.h>

void setup()
{
Serial.begin(115200);
}

void loop()
{
Serial.println(analogRead(PIN_POT));
delay(100);
}
18 changes: 18 additions & 0 deletions examples/light_serial/light_serial.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* light_serial.ino
* Reads the on-board photoresistor sensor and displays the reading.
* Updates at 10Hz and works well with the plotter utility!
*/

#include <lglearning.h>

void setup()
{
Serial.begin(115200);
}

void loop()
{
Serial.println(analogRead(PIN_LIGHT_SENSOR));
delay(100);
}
61 changes: 61 additions & 0 deletions examples/play_song/play_song.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* play_song.ino
* Plays a song to demonstrate using the buzzer
*/

#include <lglearning.h>

void setup()
{
pinMode(PIN_BUZZER, OUTPUT);
}

void loop()
{
// Setup the notes of the melody
int melody[] = {
NOTE_G4, NOTE_A4, NOTE_B4, NOTE_C5,
NOTE_B4, NOTE_A4, NOTE_C5, NOTE_B4,
0, NOTE_G4, NOTE_A4, NOTE_AS4,
NOTE_B4, NOTE_A4, NOTE_G4, NOTE_F4,
NOTE_E4, 0, NOTE_B3, NOTE_C4,
NOTE_D4, 0, NOTE_E4, NOTE_DS4,
NOTE_E4, NOTE_D4, NOTE_C4, NOTE_E4,
NOTE_E4, NOTE_D4, NOTE_D4, NOTE_CS4,
NOTE_D4, 0, NOTE_G3, NOTE_E4,
NOTE_D4, NOTE_D4, NOTE_C4, NOTE_E4,
NOTE_D4, NOTE_D4, NOTE_C4, NOTE_C4,
NOTE_B3, NOTE_D4, NOTE_C4, NOTE_B3
};

int noteDurations[] = {
8, 8, 8, 4,
4, 4, 4, 2,
8, 8, 8, 8,
4, 4, 4, 4,
2, 8, 8, 8,
8, 8, 4, 8,
8, 8, 8, 8,
8, 8, 8, 8,
4, 8, 8, 8,
8, 8, 8, 8,
8, 8, 8, 8,
8, 8, 8, 8,
};

// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 48; thisNote++)
{
// to calculate the note duration, take one second divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000 / noteDurations[thisNote];
tone(PIN_BUZZER, melody[thisNote], noteDuration);

// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(PIN_BUZZER);
}
}
211 changes: 211 additions & 0 deletions examples/shield_test/shield_test.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
/*
* shield_test.ino
* Tests and demonstrates all of the shield functions work and how to use them.
* This is used for factory test and can be used both as a learning and
* troubleshooting resource!
*
* IMPORTANT - For this to work properly, set the line ending in the serial monitor
* to be "Newline"
*/

#include <lglearning.h>

void setup()
{
// Setup the pin modes
pinMode(PIN_LED_BLUE, OUTPUT);
pinMode(PIN_LED_RED, OUTPUT);
pinMode(PIN_LED_YELLOW, OUTPUT);
pinMode(PIN_LED_GREEN, OUTPUT);;
pinMode(PIN_BUZZER, OUTPUT);
pinMode(PIN_SWITCH_A, INPUT);
pinMode(PIN_SWITCH_B, INPUT);
pinMode(PIN_SWITCH_C, INPUT);
pinMode(PIN_SWITCH_D, INPUT);

// Start a serial connection
Serial.begin(115200);
}

void waitForEnter(void)
{
// Waits to receive a line ending
while(1)
{
if(Serial.read() != -1)
{
Serial.read();
break;
}
}
}

void testLEDS(void)
{
// Check that each LED works and is the correct color
Serial.println("Press enter if blue LED is on.");
digitalWrite(PIN_LED_BLUE, HIGH);
waitForEnter();
digitalWrite(PIN_LED_BLUE, LOW);

Serial.println("Press enter if red LED is on.");
digitalWrite(PIN_LED_RED, HIGH);
waitForEnter();
digitalWrite(PIN_LED_RED, LOW);

Serial.println("Press enter if yellow LED is on.");
digitalWrite(PIN_LED_YELLOW, HIGH);
waitForEnter();
digitalWrite(PIN_LED_YELLOW, LOW);

Serial.println("Press enter if green LED is on.");
digitalWrite(PIN_LED_GREEN, HIGH);
waitForEnter();
digitalWrite(PIN_LED_GREEN, LOW);
}


void testTemperature(void)
{
// See if the temperature sensor reads a reasonable value.
Serial.println("Check that the temperatures below seem reasonable (degC). Press enter to continue.");
for(int i=0; i<5; i++)
{
Serial.println(readTemperatureCelsius());
}
waitForEnter();
}


void testBuzzer(void)
{
// Play a little song on the buzzer
Serial.println("Verify that the buzzer plays a song. Press enter to continue.");
int melody[] = {
NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};

int noteDurations[] = {
4, 8, 8, 4, 4, 4, 4, 4
};

// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 8; thisNote++) {

// to calculate the note duration, take one second divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000 / noteDurations[thisNote];
tone(PIN_BUZZER, melody[thisNote], noteDuration);

// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(PIN_BUZZER);
}
waitForEnter();
}


void testKnob(void)
{
// Check that the potentiometer works
Serial.println("Turn the knob and verify that the numbers change 0-1023. Press enter to exit.");
delay(3000);
while(1)
{
delay(100);
Serial.println(analogRead(PIN_POT));
if(Serial.read() != -1)
{
Serial.read();
break;
}
}
}


void testLight(void)
{
// Verify that the light sensor works properly.
Serial.println("Cover/uncover the light sensor and verify that the numbers change. Press enter to exit.");
delay(3000);
while(1)
{
delay(100);
Serial.println(analogRead(PIN_LIGHT_SENSOR));
if(Serial.read() != -1)
{
Serial.read();
break;
}
}
}


void testButtons(void)
{
// Verify that the buttons work
Serial.println("Press buttons and verify LED by them comes on. Press enter when done with all four buttons.");
while(1)
{
// Switch A
if (digitalRead(PIN_SWITCH_A))
{
digitalWrite(PIN_LED_GREEN, HIGH);
}
else
{
digitalWrite(PIN_LED_GREEN, LOW);
}

// Switch B
if (digitalRead(PIN_SWITCH_B))
{
digitalWrite(PIN_LED_RED, HIGH);
}
else
{
digitalWrite(PIN_LED_RED, LOW);
}

// Switch C
if (digitalRead(PIN_SWITCH_C))
{
digitalWrite(PIN_LED_BLUE, HIGH);
}
else
{
digitalWrite(PIN_LED_BLUE, LOW);
}

// Switch D
if (digitalRead(PIN_SWITCH_D))
{
digitalWrite(PIN_LED_YELLOW, HIGH);
}
else
{
digitalWrite(PIN_LED_YELLOW, LOW);
}

if(Serial.read() != -1)
{
Serial.read();
break;
}
}
}

void loop()
{
// Run through the tests forever!
testLEDS();
testTemperature();
testBuzzer();
testKnob();
testLight();
testButtons();
Serial.println("Complete! Starting again!");
}
Loading

0 comments on commit ac05fca

Please sign in to comment.