First commit

This commit is contained in:
Vikturix 2023-02-14 21:16:47 +00:00
commit bdcfde4821
26 changed files with 1455 additions and 0 deletions

43
Peter D4/Peter D4.ino Normal file
View File

@ -0,0 +1,43 @@
//LED pins
int peter1 = 10;
int peter2 = 11;
int peter3 = 12;
//Switch Pins
int switchyone = 2; //Red LED
int switchytwo = 3; //Green LED
int switchythree = 4; // Blue LED
void setup() {
// setting up input and output
pinMode(peter1,OUTPUT);
pinMode(peter2,OUTPUT);
pinMode(peter3,OUTPUT);
pinMode(switchyone,INPUT);
pinMode(switchytwo,INPUT);
pinMode(switchythree,INPUT);
}
//Now for the code
void loop() {
if (digitalRead(switchyone) == HIGH){ // Check switch one
digitalWrite(peter1,HIGH);
}
else {
digitalWrite(peter1,LOW);
}
if (digitalRead(switchytwo) == HIGH){ // Check switch two
digitalWrite(peter2,HIGH);
}
else {
digitalWrite(peter2,LOW);
}
if (digitalRead(switchythree) == HIGH){ //Check switch three
digitalWrite(peter3,HIGH);
}
else {
digitalWrite(peter3,LOW);
}
}

View File

@ -0,0 +1,57 @@
int red = 5; //red led at pin
int green = 6; //green led at pin
int blue = 7; //blue led at pin
int redswitch = 8; //reading of switch at pin 8
int greenswitch = 9; //reading of switch at pin 9
int blueswitch = 10; //reading of switch at pin 10
int counter; //counts
int redtimer = 500; //length of red light's flashing
int greentimer = 700; //length of green light's flashing
int bluetimer = 900; //length of blue light's flashing
void setup() {
// put your setup code here, to run once:
pinMode(red,OUTPUT);
pinMode(green,OUTPUT);
pinMode(blue,OUTPUT);
pinMode(redswitch,INPUT);
pinMode(greenswitch,INPUT);
pinMode(blueswitch,INPUT);
counter = 0;
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(redswitch) == HIGH) {
if (((counter / redtimer) % 2) == 0) {
digitalWrite(red,HIGH);
} else {
digitalWrite(red,LOW);
}
} else {
digitalWrite(red,LOW);
}
if (digitalRead(greenswitch) == HIGH) {
if (((counter / greentimer) % 2) == 0) {
digitalWrite(green,HIGH);
} else {
digitalWrite(green,LOW);
}
} else {
digitalWrite(green,LOW);
}
if (digitalRead(blueswitch) == HIGH) {
if (((counter / bluetimer) % 2) == 0) {
digitalWrite(blue,HIGH);
} else {
digitalWrite(blue,LOW);
}
} else {
digitalWrite(blue,LOW);
}
counter = counter + 1;
delay(1);
}

View File

@ -0,0 +1,61 @@
int red = 9;
int blue = 7;
int green = 8;
String rH;
String gH;
String bH;
int rV;
int gV;
int bV;
long counter;
String COLOUR = "#AAAAAA";
void setup() {
// put your setup code here, to run once:
counter = 0;
pinMode(red,OUTPUT);
pinMode(green,OUTPUT);
pinMode(blue,OUTPUT);
rH = COLOUR.charAt(1);
rH.concat(COLOUR.charAt(2));
gH = COLOUR.charAt(3);
gH.concat(COLOUR.charAt(4));
bH = COLOUR.charAt(5);
bH.concat(COLOUR.charAt(6));
rV = strtoul(rH.c_str(),NULL,16);
gV = strtoul(gH.c_str(),NULL,16);
bV = strtoul(bH.c_str(),NULL,16);
/*Serial.begin(9600);
Serial.println(rV);
Serial.println(gV);
Serial.println(bV);*/
}
void loop() {
// put your main code here, to run repeatedly:
int temp = counter % 256;
if (temp < rV) {
digitalWrite(red,HIGH);
} else {
digitalWrite(red,LOW);
}
if (temp < gV) {
digitalWrite(green,HIGH);
} else {
digitalWrite(green,LOW);
}
if (temp < bV) {
digitalWrite(blue,HIGH);
} else {
digitalWrite(blue,LOW);
}
counter += 1;
delayMicroseconds(10);
}

View File

@ -0,0 +1,9 @@
The MIT License (MIT)
Copyright (c) 2015 Deferred Procrastination (DPRV LTD)
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.

116
libraries/Lewis/README.md Normal file
View File

@ -0,0 +1,116 @@
Lewis
=====
A morse code interpreter: making your [Morse](https://en.wikipedia.org/wiki/Inspector_Morse_(TV_series)) easier to use and process.
Lewis is a Serial-type library for converting variable data to morse code output, or converting morse code input into strings and numbers. You can use Lewis to send and receive morse code from your Arduino, and even allow you to converse, send instructions, get status or transfer data using one pin (simplex) or two for full duplex communication.
Lewis can be used either as a set of blocking functions (pulsing out will stop any other commands until finished) or contains an interrupt routine for you to call or insert where ever suits your program best, using the timer, pin change or hardware interrupt that you have free.
Using Lewis
-----------
However you use Lewis, after installing the library (e.g. using the [library manager](https://www.arduino.cc/en/Guide/Libraries#toc2) to import it), you will have to include the library header file at the top of your sketch:
```cpp
#include "Lewis.h"
```
And instantiate the Lewis class of functions with a name that you use later. I use `Morse` but you can choose whatever name you like, as long as you are consistent through the sketch:
```cpp
Lewis Morse;
```
Using Lewis requires calling the begin function in `setup()`, to choose the input and output pins, the pulse rate, and if you will be using the interrupt function:
```cpp
Morse.begin(rx_pin, tx_pin, words_per_minute, use_interrupts);
// e.g.
Morse.begin(2, 9, 20, false);
// you can specify the same input and output pin and Lewis will
// switch modes as necessary
Morse.begin(9, 9, 20, false);
// or uses the short version that assumes 20WPM and no interrupts:
Morse.begin(9);
// if interrupts are required, use the long version:
Morse.begin(9, 9, 20, true);
```
Sending morse code
------------------
Lewis uses the same function types as the [Serial library](https://www.arduino.cc/en/Reference/Serial) so data can be sent using the `print` and `write` commands:
```cpp
// from the message_out example
Morse.print("ok"); // will send: ---/-.-
Morse.write('s'); // will send: ...
```
in the default initiation, the output code will be “blocking” — that is, it will stop at the print line while until it has finished sending the full code. This is fine for small implementations, but for more complex code, you'll want to keep running your main code, and have the morse code sent in the background.
If you call `begin` with `use_interrupts` set as `true`, then you will need to call `Morse.timerISR()` frequently enough that it can check if any dots or dashes need sending out, without the listener hearing any inaccuracy in the tone length. 100Hz seems to work nicely.
Lewis does not attach a timer interrupt when initialised (so as not to clash with anything you're already doing), so you will need to include one in your sketch. The examples use the [TimerOne](https://github.com/PaulStoffregen/TimerOne) library for the interrupt.
```cpp
// from the non_blocking_out example:
// additionally include the TimerOne library
#include <TimerOne.h>
void setup() {
// start Lewis with interrupts
Morse.begin(2, 9, 20, true);
// start TimerOne running at 100Hz
Timer1.initialize(10000);
// call the MorseISR function from below, each time the timer fires
Timer1.attachInterrupt(myISR);
}
// create a function that calls the Lewis ISR
void myISR()
{
// inclued this function to actually output morse code, and check for input
Morse.timerISR();
}
```
Receiving morse
---------------
Lewis needs to watch the receiving pin of your choice for it's `LOW → HIGH` changes often enough that it can see every change and accurately time the duration between each one to decode the dots, dashes, inter-letter spaces and inter-word spaces. To do so, your script will have do call the `checkIncoming` function rapidly enough (ideally 100 times or more per second) to pass decode the morse stream and pass them into the receiving buffer.
If you're using the interrupt initialisation of Lewis, then `checkIncoming` is already included in the `timerISR` function, so Lewis will already be watching your receive pin for button presses. If you're using the standard, non-interrupting initialisation then just putting `Morse.checkIncoming()` in a fast loop will be enough.
```cpp
//from the read_respond example
void loop() {
// call checkIncoming often enough to catch the incoming presses
Morse.checkIncoming();
if (Morse.available()) {
char c = Morse.read();
if (c == 'k') {
delay(100);
Morse.print("ok");
}
}
}
```
With such a small loop, the checking function is not likely to miss any button press changes, but you could also run `checkIncoming` as part of a [hardware interrupt](https://www.arduino.cc/en/Reference/AttachInterrupt) or [pin change interrupt](http://www.geertlangereis.nl/Electronics/Pin_Change_Interrupts/PinChange_en.html) if necessary.
To process data that's in the receive buffer, you can check if there is data, and process that as you normally would with Serial input:
```cpp
// first check if there's anything to process:
if (Morse.available();) { // available returns the number of characters available
// read grabs the next character from the buffer:
char c = Morse.read();
// or peek checks the next character, but without moving the buffer index forward
char p = Morse.peek();
// any following call of peek (or the next read) will still return the same letter
}
```

View File

@ -0,0 +1,20 @@
#include "Lewis.h"
Lewis Morse;
void setup() {
// single recieve (RX) and transmit (TX) pin (simplex)
// Lewis will switch the pin to OUTPUT as required to send
Morse.begin(9);
}
void loop() {
Morse.print("ok");
delay(1000);
Morse.write('s');
delay(1000);
Morse.print(1);
delay(1000);
Morse.print(1.10);
delay(1000);
}

View File

@ -0,0 +1,28 @@
#include "Lewis.h"
#include <TimerOne.h>
Lewis Morse;
void setup() {
// use the long form of Morse.begin to allow interrupts:
// Morse.begin(rx_pin, tx_pin, words_per_minute, use_interrupts)
Morse.begin(2, 9, 20, true);
Timer1.initialize(10000);
Timer1.attachInterrupt(myISR);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
Morse.print("ok");
for (int i=0; i<4; i++) {
digitalWrite(LED_BUILTIN, HIGH);
delay(250);
digitalWrite(LED_BUILTIN, LOW);
delay(250);
}
}
void myISR()
{
Morse.timerISR();
}

View File

@ -0,0 +1,22 @@
#include "Lewis.h"
Lewis Morse;
void setup() {
// single recieve (RX) and transmit (TX) pin (simplex)
// Lewis will switch the pin to OUTPUT as required to send
Morse.begin(9);
}
void loop() {
// call checkIncoming often enough to catch the incoming presses
Morse.checkIncoming();
if (Morse.available()) {
char c = Morse.read();
if (c == 'k') {
delay(100);
Morse.print("ok");
}
}
}

View File

@ -0,0 +1,38 @@
#include "Lewis.h"
#include <TimerOne.h>
Lewis Morse;
void setup() {
// open the serial port
Serial.begin(9600);
// wait for serial port to connect on 32u4 boards (eg. Leonardo)
while (!Serial){;}
// use the long form of Morse.begin to allow interrupts:
// Morse.begin(rx_pin, tx_pin, words_per_minute, use_interrupts)
Morse.begin(2, 9, 20, true);
// use the TimerOne library for a 100Hz timer interrupt
Timer1.initialize(10000);
Timer1.attachInterrupt(MorseISR);
}
void loop() {
// send each serial byte to Morse output
if (Serial.available()) {
int inByte = Serial.read();
Morse.write(inByte);
}
// send each Morse byte to serial port
if (Morse.available()) {
int inByte = Morse.read();
Serial.write(inByte);
}
delay(500);
}
// your own defined interrupt function that includes the Morse.timerISR call
void MorseISR()
{
Morse.timerISR();
}

View File

@ -0,0 +1,38 @@
#include "Lewis.h"
#include <TimerOne.h>
Lewis Morse;
void setup() {
// open the serial port
Serial.begin(9600);
// wait for serial port to connect on 32u4 boards (eg. Leonardo)
while (!Serial){;}
// use the long form of Morse.begin to allow interrupts:
// Morse.begin(rx_pin, tx_pin, words_per_minute, use_interrupts)
Morse.begin(9, 9, 20, true);
// use the TimerOne library for a 100Hz timer interrupt
Timer1.initialize(10000);
Timer1.attachInterrupt(MorseISR);
}
void loop() {
// send each serial byte to Morse output
if (Serial.available()) {
int inByte = Serial.read();
Morse.write(inByte);
}
// send each Morse byte to serial port
if (Morse.available()) {
int inByte = Morse.read();
Serial.write(inByte);
}
delay(500);
}
// your own defined interrupt function that includes the Morse.timerISR call
void MorseISR()
{
Morse.timerISR();
}

View File

@ -0,0 +1,11 @@
EESchema-DOCLIB Version 2.0
#
$CMP 555_timer
F ns/lm555.pdf
$ENDCMP
#
$CMP LM555N
F ns/lm555.pdf
$ENDCMP
#
#End Doc Library

View File

@ -0,0 +1,11 @@
EESchema-DOCLIB Version 2.0
#
$CMP 555_timer
F ns/lm555.pdf
$ENDCMP
#
$CMP LM555N
F ns/lm555.pdf
$ENDCMP
#
#End Doc Library

View File

@ -0,0 +1,124 @@
EESchema-LIBRARY Version 2.3
#encoding utf-8
#
# +5V
#
DEF +5V #PWR 0 0 Y Y 1 F P
F0 "#PWR" 0 -150 50 H I C CNN
F1 "+5V" 0 140 50 H V C CNN
F2 "" 0 0 60 H V C CNN
F3 "" 0 0 60 H V C CNN
DRAW
P 2 0 1 0 -30 50 0 100 N
P 2 0 1 0 0 0 0 100 N
P 2 0 1 0 0 100 30 50 N
X +5V 1 0 0 0 U 50 50 1 1 W N
ENDDRAW
ENDDEF
#
# 555_timer
#
DEF 555_timer U 0 40 Y Y 1 F N
F0 "U" 0 100 70 H V C CNN
F1 "555_timer" 0 -100 70 H V C CNN
F2 "" 0 0 60 H V C CNN
F3 "" 0 0 60 H V C CNN
DRAW
X GND 1 0 -400 0 U 60 60 0 0 W
X VCC 8 0 400 0 D 60 60 0 0 W
S -400 -400 400 400 0 1 0 N
X TR 2 -700 -250 300 R 60 60 1 1 I
X Q 3 700 250 300 L 60 60 1 1 O
X R 4 700 -250 300 L 60 60 1 1 I I
X CV 5 700 0 300 L 60 60 1 1 I
X THR 6 -700 0 300 R 60 60 1 1 I
X DIS 7 -700 250 300 R 60 60 1 1 I
ENDDRAW
ENDDEF
#
# C
#
DEF C C 0 10 N Y 1 F N
F0 "C" 25 100 50 H V L CNN
F1 "C" 25 -100 50 H V L CNN
F2 "" 38 -150 30 H V C CNN
F3 "" 0 0 60 H V C CNN
$FPLIST
C?
C_????_*
C_????
SMD*_c
Capacitor*
$ENDFPLIST
DRAW
P 2 0 1 20 -80 -30 80 -30 N
P 2 0 1 20 -80 30 80 30 N
X ~ 1 0 150 110 D 40 40 1 1 P
X ~ 2 0 -150 110 U 40 40 1 1 P
ENDDRAW
ENDDEF
#
# GND
#
DEF GND #PWR 0 0 Y Y 1 F P
F0 "#PWR" 0 -250 50 H I C CNN
F1 "GND" 0 -150 50 H V C CNN
F2 "" 0 0 60 H V C CNN
F3 "" 0 0 60 H V C CNN
DRAW
P 6 0 1 0 0 0 0 -50 50 -50 0 -100 -50 -50 0 -50 N
X GND 1 0 0 0 D 50 50 1 1 W N
ENDDRAW
ENDDEF
#
# PIEZO
#
DEF PIEZO P 0 40 Y Y 1 F N
F0 "P" 200 150 60 H V C CNN
F1 "PIEZO" 250 -150 60 H V C CNN
F2 "" 0 0 60 H V C CNN
F3 "" 0 0 60 H V C CNN
DRAW
X ~ ~ 0 -200 100 U 60 60 0 0 U
X ~ ~ 0 200 100 D 60 60 0 0 U
S -150 50 150 -50 0 1 0 N
P 2 0 1 0 -150 -100 150 -100 N
P 2 0 1 0 -150 100 150 100 N
ENDDRAW
ENDDEF
#
# POT
#
DEF POT RV 0 40 Y N 1 F N
F0 "RV" 0 -100 50 H V C CNN
F1 "POT" 0 0 50 H V C CNN
F2 "" 0 0 60 H V C CNN
F3 "" 0 0 60 H V C CNN
DRAW
S -150 50 150 -50 0 1 0 N
P 3 0 1 0 0 50 -20 70 20 70 F
X 1 1 -250 0 100 R 40 40 1 1 P
X 2 2 0 150 80 D 40 40 1 1 P
X 3 3 250 0 100 L 40 40 1 1 P
ENDDRAW
ENDDEF
#
# R
#
DEF R R 0 0 N Y 1 F N
F0 "R" 80 0 50 V V C CNN
F1 "R" 0 0 50 V V C CNN
F2 "" -70 0 30 V V C CNN
F3 "" 0 0 30 H V C CNN
$FPLIST
R_*
Resistor_*
$ENDFPLIST
DRAW
S -40 -100 40 100 0 1 10 N
X ~ 1 0 150 50 D 60 60 1 1 P
X ~ 2 0 -150 50 U 60 60 1 1 P
ENDDRAW
ENDDEF
#
#End Library

View File

@ -0,0 +1 @@
(kicad_pcb (version 4) (host kicad "dummy file") )

View File

@ -0,0 +1,60 @@
update=Thu 03 Dec 2015 17:48:24 GMT
version=1
last_client=kicad
[pcbnew]
version=1
LastNetListRead=
UseCmpFile=1
PadDrill=0.600000000000
PadDrillOvalY=0.600000000000
PadSizeH=1.500000000000
PadSizeV=1.500000000000
PcbTextSizeV=1.500000000000
PcbTextSizeH=1.500000000000
PcbTextThickness=0.300000000000
ModuleTextSizeV=1.000000000000
ModuleTextSizeH=1.000000000000
ModuleTextSizeThickness=0.150000000000
SolderMaskClearance=0.000000000000
SolderMaskMinWidth=0.000000000000
DrawSegmentWidth=0.200000000000
BoardOutlineThickness=0.100000000000
ModuleOutlineThickness=0.150000000000
[cvpcb]
version=1
NetIExt=net
[eeschema]
version=1
LibDir=
[eeschema/libraries]
LibName1=power
LibName2=device
LibName3=transistors
LibName4=conn
LibName5=linear
LibName6=regul
LibName7=74xx
LibName8=cmos4000
LibName9=adc-dac
LibName10=memory
LibName11=xilinx
LibName12=microcontrollers
LibName13=dsp
LibName14=microchip
LibName15=analog_switches
LibName16=motorola
LibName17=texas
LibName18=intel
LibName19=audio
LibName20=interface
LibName21=digital-audio
LibName22=philips
LibName23=display
LibName24=cypress
LibName25=siliconi
LibName26=opto
LibName27=atmel
LibName28=contrib
LibName29=valves
[general]
version=1

View File

@ -0,0 +1,199 @@
EESchema Schematic File Version 2
LIBS:power
LIBS:device
LIBS:transistors
LIBS:conn
LIBS:linear
LIBS:regul
LIBS:74xx
LIBS:cmos4000
LIBS:adc-dac
LIBS:memory
LIBS:xilinx
LIBS:microcontrollers
LIBS:dsp
LIBS:microchip
LIBS:analog_switches
LIBS:motorola
LIBS:texas
LIBS:intel
LIBS:audio
LIBS:interface
LIBS:digital-audio
LIBS:philips
LIBS:display
LIBS:cypress
LIBS:siliconi
LIBS:opto
LIBS:atmel
LIBS:contrib
LIBS:valves
LIBS:key-cache
EELAYER 25 0
EELAYER END
$Descr A4 11693 8268
encoding utf-8
Sheet 1 1
Title ""
Date ""
Rev ""
Comp ""
Comment1 ""
Comment2 ""
Comment3 ""
Comment4 ""
$EndDescr
$Comp
L 555_timer U1
U 1 1 56607DEB
P 2000 1750
F 0 "U1" H 2000 1850 70 0000 C CNN
F 1 "555_timer" H 2000 1650 70 0000 C CNN
F 2 "" H 2000 1750 60 0000 C CNN
F 3 "" H 2000 1750 60 0000 C CNN
1 2000 1750
1 0 0 -1
$EndComp
$Comp
L +5V #PWR01
U 1 1 56607E83
P 2000 900
F 0 "#PWR01" H 2000 750 50 0001 C CNN
F 1 "+5V" H 2000 1040 50 0000 C CNN
F 2 "" H 2000 900 60 0000 C CNN
F 3 "" H 2000 900 60 0000 C CNN
1 2000 900
1 0 0 -1
$EndComp
$Comp
L GND #PWR02
U 1 1 56607E99
P 2000 2650
F 0 "#PWR02" H 2000 2400 50 0001 C CNN
F 1 "GND" H 2000 2500 50 0000 C CNN
F 2 "" H 2000 2650 60 0000 C CNN
F 3 "" H 2000 2650 60 0000 C CNN
1 2000 2650
1 0 0 -1
$EndComp
Text GLabel 2800 2000 2 60 Input ~ 0
ACTIVE
$Comp
L C C2
U 1 1 56607F26
P 3350 1950
F 0 "C2" H 3375 2050 50 0000 L CNN
F 1 "0.1µF" H 3375 1850 50 0000 L CNN
F 2 "" H 3388 1800 30 0000 C CNN
F 3 "" H 3350 1950 60 0000 C CNN
1 3350 1950
1 0 0 -1
$EndComp
$Comp
L R R1
U 1 1 56607F5A
P 1100 1250
F 0 "R1" V 1180 1250 50 0000 C CNN
F 1 "12K" V 1100 1250 50 0000 C CNN
F 2 "" V 1030 1250 30 0000 C CNN
F 3 "" H 1100 1250 30 0000 C CNN
1 1100 1250
1 0 0 -1
$EndComp
$Comp
L R R2
U 1 1 56607F78
P 1100 1750
F 0 "R2" V 1180 1750 50 0000 C CNN
F 1 "270K" V 1100 1750 50 0000 C CNN
F 2 "" V 1030 1750 30 0000 C CNN
F 3 "" H 1100 1750 30 0000 C CNN
1 1100 1750
1 0 0 -1
$EndComp
$Comp
L C C1
U 1 1 56607FA1
P 1100 2200
F 0 "C1" H 1125 2300 50 0000 L CNN
F 1 "0.01µF" H 1125 2100 50 0000 L CNN
F 2 "" H 1138 2050 30 0000 C CNN
F 3 "" H 1100 2200 60 0000 C CNN
1 1100 2200
1 0 0 -1
$EndComp
Wire Wire Line
2000 900 2000 1350
Wire Wire Line
2000 2150 2000 2650
Wire Wire Line
2700 2000 2800 2000
Wire Wire Line
3350 2100 3350 2250
Wire Wire Line
3350 2250 2000 2250
Connection ~ 2000 2250
Wire Wire Line
2700 1750 3350 1750
Wire Wire Line
3350 1750 3350 1800
Wire Wire Line
1100 2350 1100 2450
Wire Wire Line
1100 2450 2000 2450
Connection ~ 2000 2450
Wire Wire Line
1100 2000 1300 2000
Wire Wire Line
1100 1900 1100 2050
Connection ~ 1100 2000
Wire Wire Line
1300 1750 1250 1750
Wire Wire Line
1250 1750 1250 2000
Connection ~ 1250 2000
Wire Wire Line
1300 1500 1100 1500
Wire Wire Line
1100 1400 1100 1600
Connection ~ 1100 1500
Wire Wire Line
1100 1100 1100 1000
Wire Wire Line
1100 1000 2000 1000
Connection ~ 2000 1000
$Comp
L POT RV1
U 1 1 566081EC
P 4050 1500
F 0 "RV1" H 4050 1400 50 0000 C CNN
F 1 "10K" H 4050 1500 50 0000 C CNN
F 2 "" H 4050 1500 60 0000 C CNN
F 3 "" H 4050 1500 60 0000 C CNN
1 4050 1500
-1 0 0 1
$EndComp
$Comp
L PIEZO P1
U 1 1 566082B3
P 4050 2100
F 0 "P1" H 4250 2250 60 0000 C CNN
F 1 "PIEZO" H 4300 1950 60 0000 C CNN
F 2 "" H 4050 2100 60 0000 C CNN
F 3 "" H 4050 2100 60 0000 C CNN
1 4050 2100
1 0 0 -1
$EndComp
Wire Wire Line
2700 1500 3800 1500
Wire Wire Line
4050 1650 4050 1900
Wire Wire Line
4050 2300 4050 2350
Wire Wire Line
4050 2350 2000 2350
Connection ~ 2000 2350
NoConn ~ 4300 1500
Text Notes 2450 1100 0 60 ~ 0
261.4Hz Piezo Tone Generator
$EndSCHEMATC

View File

@ -0,0 +1,22 @@
######################
# Datatypes (KEYWORD1)
######################
Lewis KEYWORD1
######################
# Funtions (KEYWORD2)
######################
begin KEYWORD2
available KEYWORD2
read KEYWORD2
peak KEYWORD2
flush KEYWORD2
flushRX KEYWORD2
flushTX KEYWORD2
write KEYWORD2
#######################
# Constants (LITERAL1)
#######################

View File

@ -0,0 +1,23 @@
{
"name": "Lewis",
"version": "0.1.4",
"description": "A Serial-style morse code interpreter: making your Morse easier to use and process.",
"keywords": "Communication, Serial, Morse, Code, dit, dah",
"repository":
{
"type": "git",
"url": "https://github.com/DefProc/lewis.git"
},
"authors":
[
{
"name": "Patrick Fenner",
"email": "contact@defproc.co.uk",
"url": "https://defproc.co.uk/",
"maintainer": true
}
],
"license": "MIT",
"frameworks": "*",
"platforms": "*"
}

View File

@ -0,0 +1,9 @@
name=Lewis
version=0.1.4
author=Patrick Fenner <contact@defproc.co.uk>
maintainer=Patrick Fenner <contact@defproc.co.uk>
sentence=A morse code stream/print interpreter
paragraph=Lewis helps with receiving and sending morse code from a microcontroller
category=Communication
url=https://git.defproc.co.uk/DefProc/Lewis/
architectures=*

View File

@ -0,0 +1,338 @@
#include <inttypes.h>
#include "Arduino.h"
#include "Lewis.h"
void Lewis::begin(uint8_t rx_pin, uint8_t tx_pin, uint8_t words_per_minute, uint8_t use_interrupts)
{
_rx_pin = rx_pin;
_tx_pin = tx_pin;
_pulse_duration = 1200/words_per_minute;
_use_interrupts = use_interrupts;
if (_rx_pin != _tx_pin) {
pinMode(_tx_pin, OUTPUT);
digitalWrite(_tx_pin, LOW);
_samePin = false;
}
pinMode(_rx_pin, INPUT);
}
int Lewis::available(void)
{
int num_chars = 0;
if (_rx_buffer_head != _rx_buffer_tail) {
// count the number of inter-letter spaces up to the head
rx_buffer_index_t position = _rx_buffer_tail;
while (position != _rx_buffer_head) {
position = (position +1) % MORSE_RX_BUFFER_SIZE;
// show the buffer for debugging:
/*
Serial.print(position);
Serial.write(':');
Serial.print(_rx_buffer[position]);
Serial.write(',');
*/
if (_rx_buffer[position] == INTERLETTER_SPACE || _rx_buffer[position] == INTERWORD_SPACE) num_chars++;
}
// show the buffer for debugging:
/*
Serial.println();
Serial.println(num_chars);
*/
}
return num_chars;
}
int Lewis::peek(void)
{
if (_rx_buffer_head == _rx_buffer_tail) {
return -1;
} else {
return parseMorse(false);
}
}
int Lewis::read(void)
{
// if the head isn't ahead of the tail, we don't have any characters
if (_rx_buffer_head == _rx_buffer_tail) {
return -1;
} else {
return parseMorse(true);
}
}
char Lewis::parseMorse(bool advance_position)
{
// do the actual parsing
// store the inital buffer tail position for later
rx_buffer_index_t current_tail = _rx_buffer_tail;
// and increment the position to find the next instruction
current_tail = (current_tail + 1) % MORSE_RX_BUFFER_SIZE;
// if we're at an inter-word space, send a space
if (_rx_buffer[current_tail] == INTERWORD_SPACE) {
// only record the new buffer position if we're reading
if (advance_position == true) _rx_buffer_tail = current_tail;
return ' ';
}
// otherwise lets start traversing the lookup table
_morseIndex = START_INDEX;
_indexJump = START_INDEX/2;
while (_rx_buffer[current_tail] != _rx_buffer[_rx_buffer_head]) {
// there should be something here to better handle a buffer overrun
// as it is, we'll just take what ever result that gives us.
if (_rx_buffer[current_tail] == DOT) {
_morseIndex = _morseIndex - _indexJump;
_indexJump = _indexJump/2;
} else if (_rx_buffer[current_tail] == DASH) {
_morseIndex = _morseIndex + _indexJump;
_indexJump = _indexJump/2;
} else {
break;
}
current_tail = (current_tail + 1) % MORSE_RX_BUFFER_SIZE;
}
if (advance_position == true) _rx_buffer_tail = current_tail;
// if there's an invalid character, this will return a tilde '~'
return _morseLookup[_morseIndex];
}
size_t Lewis::write(uint8_t c)
{
if (c >= 'A' && c <= 'Z') {
// convert upercase letters to lowercase
c = c + 0x20;
}
uint8_t targetLocation = 0;
for (targetLocation=0; targetLocation<=START_INDEX*2; targetLocation++) {
if (c == _morseLookup[targetLocation]) {
break;
}
}
if (targetLocation >= START_INDEX*2) {
// deal with a few extra characters without having to double the lookup table length
if (c == ' ' || c == '\n' || c == '\r') {
// translate spaces or newlines to an interword space
interwordSpace();
return 0;
} else {
// the selected character was not found in the lookup table
return 1;
}
}
// debugging
//Serial.print(targetLocation);
_morseIndex = START_INDEX;
_indexJump = START_INDEX/2;
if (_use_interrupts == false) {
// if outputting the letter directly (blocking)
if (_samePin == true) pinMode(_tx_pin, OUTPUT);
}
while (_morseIndex != targetLocation) {
if (_morseIndex < targetLocation) {
// do a dash
dash();
// move the pointer right
_morseIndex = _morseIndex + _indexJump;
} else {
// do a dot
dot();
// move the pointer left
_morseIndex = _morseIndex - _indexJump;
}
if (_indexJump == 1) {
break;
} else {
_indexJump = _indexJump/2;
}
}
interletterSpace();
if (_use_interrupts == false) {
// if outputting the letter directly (blocking)
if (_samePin == true) pinMode(_rx_pin, INPUT);
}
// show the buffer for debugging:
/*
for (int i=_tx_buffer_tail; i != _tx_buffer_head; i = (i+1) % MORSE_TX_BUFFER_SIZE) {
Serial.print(i);
Serial.write(':');
Serial.print(_tx_buffer[i]);
Serial.write(',');
}
*/
return 0;
}
void Lewis::flush()
{
// clear both buffers
flushTX();
flushRX();
}
void Lewis::flushTX()
{
_tx_buffer_tail = _tx_buffer_head;
}
void Lewis::flushRX()
{
_rx_buffer_tail = _rx_buffer_head;
}
void Lewis::dot()
{
if (_use_interrupts == true) {
_tx_buffer_head = (_tx_buffer_head + 1) % MORSE_TX_BUFFER_SIZE;
_tx_buffer[_tx_buffer_head] = DOT;
} else {
digitalWrite(_tx_pin, HIGH);
delay(_pulse_duration*DOT);
digitalWrite(_tx_pin, LOW);
delay(_pulse_duration);
}
}
void Lewis::dash()
{
if (_use_interrupts == true) {
_tx_buffer_head = (_tx_buffer_head + 1) % MORSE_TX_BUFFER_SIZE;
_tx_buffer[_tx_buffer_head] = DASH;
} else {
digitalWrite(_tx_pin, HIGH);
delay(_pulse_duration*DASH);
digitalWrite(_tx_pin, LOW);
delay(_pulse_duration);
}
}
void Lewis::interletterSpace()
{
if (_use_interrupts == true) {
_tx_buffer_head = (_tx_buffer_head + 1) % MORSE_TX_BUFFER_SIZE;
_tx_buffer[_tx_buffer_head] = INTERLETTER_SPACE;
} else {
digitalWrite(_tx_pin, LOW);
delay(_pulse_duration*INTERLETTER_SPACE);
}
}
void Lewis::interwordSpace()
{
if (_use_interrupts == true) {
_tx_buffer_head = (_tx_buffer_head + 1) % MORSE_TX_BUFFER_SIZE;
_tx_buffer[_tx_buffer_head] = INTERWORD_SPACE;
} else {
digitalWrite (_tx_pin, LOW);
delay(_pulse_duration*INTERWORD_SPACE);
}
}
void Lewis::timerISR()
{
if (_samePin) {
// if using one pin:
if (!_transmitting && _tx_buffer_head != _tx_buffer_tail) {
// block recieving when we have something in the transmit buffer
_transmitting = true;
pinMode(_rx_pin, OUTPUT);
} else if (_transmitting && _tx_buffer_head == _tx_buffer_tail){
// go back to listening when the tx buffer is empty
_transmitting = false;
pinMode(_rx_pin, INPUT);
}
}
volatile unsigned long time_now = millis();
if (_tx_buffer_tail != _tx_buffer_head && (time_now >= _next_tx)) {//} || time_now - _next_tx >= time_now)) {
// there is data to send out (the tail hasn't caught up with the head)
// AND the time of next transmit change has passed
if (_tx_state == LOW) {
if (_tx_buffer[_tx_buffer_tail] == DOT || _tx_buffer[_tx_buffer_tail] == DASH) {
// change to high if DOT or DASH
// and set the _next_tx depending on length
_tx_state = HIGH;
digitalWrite(_tx_pin, _tx_state);
_next_tx = (time_now + (_pulse_duration * _tx_buffer[_tx_buffer_tail]));
// but don't move the buffer position, we need the trailing rest first
} else {
// it's a rest, keep low and wait for the next character
_tx_state = LOW;
digitalWrite(_tx_pin, _tx_state);
_next_tx = (time_now + (_pulse_duration * _tx_buffer[_tx_buffer_tail]));
// and increment the buffer tail position
_tx_buffer_tail = (_tx_buffer_tail + 1) % MORSE_TX_BUFFER_SIZE;
}
} else {
// it's a high state, and we need to make the trailing rest
_tx_state = LOW;
digitalWrite(_tx_pin, _tx_state);
_next_tx = (time_now + _pulse_duration);
// and increment the buffer tail position
_tx_buffer_tail = (_tx_buffer_tail + 1) % MORSE_TX_BUFFER_SIZE;
}
}
if (!_transmitting) {
checkIncoming();
}
}
void Lewis::checkIncoming()
{
uint32_t current_time = millis();
uint8_t current_state = digitalRead(_rx_pin);
// we only need to do something on change or a long duration low
if (_rx_state == LOW) {
// have we been low long enough for an inter-word/letter space?
if (_rx_buffer[_rx_buffer_head] == INTERLETTER_SPACE && current_time - _last_rx >= _pulse_duration * (DOT + INTERLETTER_SPACE + INTERWORD_SPACE) + 1) {
// it's been an inter-word space (must follow an inter letter space)
_rx_buffer_head = (_rx_buffer_head + 1) % MORSE_RX_BUFFER_SIZE;
_rx_buffer[_rx_buffer_head] = INTERWORD_SPACE;
} else if ((_rx_buffer[_rx_buffer_head] == DOT || _rx_buffer[_rx_buffer_head] == DASH) && current_time - _last_rx >= _pulse_duration * (DOT + INTERLETTER_SPACE) + 1) {
// it's been an inter-letter space (must follow a dot or dash)
_rx_buffer_head = (_rx_buffer_head + 1) % MORSE_RX_BUFFER_SIZE;
_rx_buffer[_rx_buffer_head] = INTERLETTER_SPACE;
}
if (current_state == HIGH) {
// mark when the pin went high
_last_rx = current_time;
_rx_state = current_state;
}
} else if (_rx_state == HIGH && current_state == LOW) {
// the falling end of a pulse
uint32_t pulse_time = current_time - _last_rx;
if (pulse_time >= _pulse_duration * DASH) {
//record a dash
_rx_buffer_head = (_rx_buffer_head + 1) % MORSE_RX_BUFFER_SIZE;
_rx_buffer[_rx_buffer_head] = DASH;
_last_rx = current_time;
_rx_state = current_state;
} else if (pulse_time >= _pulse_duration/2){
// record a dot
_rx_buffer_head = (_rx_buffer_head + 1) % MORSE_RX_BUFFER_SIZE;
_rx_buffer[_rx_buffer_head] = DOT;
_last_rx = current_time;
_rx_state = current_state;
}
}
}

View File

@ -0,0 +1,87 @@
#ifndef Lewis_h
#define Lewis_h
#include <inttypes.h>
#include <Arduino.h>
#include "Stream.h"
#if !(defined(MORSE_TX_BUFFER_SIZE) && defined(MORSE_RX_BUFFER_SIZE))
#if (RAMEND < 1000)
#define MORSE_TX_BUFFER_SIZE 16
#define MORSE_RX_BUFFER_SIZE 16
#else
#define MORSE_TX_BUFFER_SIZE 64
#define MORSE_RX_BUFFER_SIZE 64
#endif
#endif
#if (MORSE_TX_BUFFER_SIZE>256)
typedef uint16_t tx_buffer_index_t;
#else
typedef uint8_t tx_buffer_index_t;
#endif
#if (MORSE_RX_BUFFER_SIZE>256)
typedef uint16_t rx_buffer_index_t;
#else
typedef uint8_t rx_buffer_index_t;
#endif
#define START_INDEX 64
#define DOT 1
#define DASH 3
#define INTERLETTER_SPACE 2
#define INTERWORD_SPACE 4
class Lewis : public Stream
{
protected:
volatile rx_buffer_index_t _rx_buffer_head;
volatile rx_buffer_index_t _rx_buffer_tail;
volatile uint8_t _rx_state = LOW;
volatile uint32_t _last_rx = 0;
volatile tx_buffer_index_t _tx_buffer_head;
volatile tx_buffer_index_t _tx_buffer_tail;
volatile uint8_t _tx_state = LOW;
volatile uint32_t _next_tx = 0;
volatile bool _transmitting = false;
uint8_t _rx_pin;
uint8_t _tx_pin;
uint8_t _samePin = true;
uint8_t _pulse_duration;
uint8_t _use_interrupts = true;
char parseMorse(bool advance_position = false);
void dot();
void dash();
void interletterSpace();
void interwordSpace();
uint8_t _morseIndex = START_INDEX;
uint8_t _indexJump = START_INDEX/2;
// |0 start:↓ 127|
const char* _morseLookup = "~~5~h~4~s~~~v~3~i~~~f~~~u?~_~~2~e~&~l\"~~r~+.~~~~a~~~p@~~w~~~j\'1~~~6-b~=~d~/~x~~~n~~~c;~!k~()y~~~t~7~z~~,g~~~q~~~m:8~~~~~o~9~~~0~";
// Don't put any members after these buffers, since only the first
// 32 bytes of this struct can be accessed quickly using the ldd
// instruction.
uint8_t _rx_buffer[MORSE_RX_BUFFER_SIZE];
uint8_t _tx_buffer[MORSE_TX_BUFFER_SIZE];
public:
void begin(int rx_pin) { return begin(rx_pin, rx_pin); }
void begin(uint8_t rx_pin, uint8_t tx_pin, uint8_t words_per_minute = 20, uint8_t use_interrupts = false);
int available(void);
int read(void);
int peek();
void flush();
void flushTX();
void flushRX();
size_t write(uint8_t);
void timerISR();
void checkIncoming();
//Stream() {_timeout=2000;}
};
#endif

20
light/light.ino Normal file
View File

@ -0,0 +1,20 @@
int sensorPin = A0;
int LED = 13;
int sensorValue = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(LED,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
sensorValue = analogRead(sensorPin);
digitalWrite(LED, HIGH);
delay(sensorValue);
digitalWrite(LED,LOW);
delay(sensorValue);
Serial.println(sensorValue);
}

View File

@ -0,0 +1,30 @@
#include <Lewis.h>
String lipsum;
String testing;
Lewis Morse;
int a = 0;
void setup() {
pinMode(12,INPUT);
pinMode(7,OUTPUT);
Morse.begin(3,3,20,false);
lipsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque consequat libero vitae elit scelerisque, vel auctor quam fringilla. Quisque metus tellus, sollicitudin sed nibh a, pretium tempor lectus. Etiam tincidunt felis non mattis iaculis. Maecenas tristique tortor a eros aliquet ultricies. Curabitur vitae sollicitudin nunc, sed accumsan tortor. Maecenas in ante ex. Vivamus elementum libero sed sem malesuada tincidunt. Suspendisse rhoncus justo et metus luctus faucibus. Suspendisse at orci sit amet ante lobortis tempor quis sit amet mauris. In a purus magna. Morbi gravida, neque sed mattis ullamcorper, eros lacus cursus magna, et fermentum ligula felis at risus. Cras mollis.";
testing = "Hello mum";
}
void loop() {
// put your main code here, to run repeatedly:
while (a==0) {
delay(1);
if (digitalRead(12)==HIGH) {
a=1;
}
}
a=0;
digitalWrite(7,LOW);
for (int x=0;x<testing.length();x++) {
Morse.print(testing[x]);
}
digitalWrite(7,HIGH);
delay(1000);
}

View File

@ -0,0 +1,15 @@
int peter = 11 ; //ouagadougou
void setup() {
// put your setup code here, to run once:
pinMode(peter,OUTPUT);
digitalWrite(peter,LOW);
}
void loop() {
//you are a snail
digitalWrite(peter,LOW);
delay(3000);
digitalWrite(peter,HIGH);
delay(150);
}

View File

@ -0,0 +1,31 @@
int counter = 0;
void setup() {
// put your setup code here, to run once:
pinMode(5, OUTPUT); //red light
pinMode(6, OUTPUT); //green light
}
void loop() {
// put your main code here, to run repeatedly:
int result = 0;
int red_timer = 500;
int green_timer = 700;
result = counter / red_timer;
if (result % 2 == 0) {
digitalWrite(5, HIGH);
} else {
digitalWrite(5, LOW);
}
result = counter / green_timer;
if (result % 2 == 0) {
digitalWrite(6, HIGH);
} else {
digitalWrite(6, LOW);
}
delay(1);
counter = counter + 1;
}

View File

@ -0,0 +1,42 @@
int sensor = A0;
int LED = 13;
int light;
unsigned int battery = 0;
unsigned int capacity = 50000;
unsigned int ticks = 0;
unsigned int wait = 100;
double percentage;
void setup() {
// put your setup code here, to run once:
pinMode(LED,OUTPUT);
Serial.begin(9600);
}
void PrintBatteryPercentage() {
Serial.print(ticks);
Serial.print("ms, charge at ");
percentage = 100 * ((double)battery / (double)capacity);
Serial.print(percentage);
Serial.println("%");
}
void loop() {
// put your main code here, to run repeatedly:
light = analogRead(sensor);
battery += light;
ticks += wait;
if (battery >= capacity) {
battery = capacity;
Serial.print(ticks);
Serial.print("ms ");
Serial.println("FULLY CHARGED");
ticks = 0;
delay(20000);
} else {
PrintBatteryPercentage();
}
delay(wait);
}