#define left1 32
#define left2 26
#define right2 30
#define right1 28
#define eLeft A8
#define eRight A9
//********************************************************************************************************************************************************************************************
#include <LiquidCrystal.h>
int lcd_key = 0;
int adc_key_in = 0;
// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
//********************************************************************************************************************************************************************************************
String data="";
int mark = 0;
boolean Mark_Start=false;
boolean valid=false;
String GGAUTCtime,GGAlatitude,GGAlongitude,GPStatus,SatelliteNum,HDOPfactor,Height,
PositionValid,RMCUTCtime,RMClatitude,RMClongitude,Speed,Direction,Date,Declination,Mode;
//********************************************************************************************************************************************************************************************
int longitude, latitude;
//********************************************************************************************************************************************************************************************
void setup() {
pinMode(right1, OUTPUT);
pinMode(right2, OUTPUT);
pinMode(left1, OUTPUT);
pinMode(left2, OUTPUT);
pinMode(eLeft, OUTPUT);
pinMode(eRight, OUTPUT);
digitalWrite(eLeft, HIGH);
digitalWrite(eRight, HIGH);
//********************************************************************************************************************************************************************************************
Serial.begin(9600);
Serial1.begin(9600);
Serial.println(0);
delay(1000);
pinMode(21, OUTPUT);
digitalWrite (21, HIGH);
pinMode(20, OUTPUT);
digitalWrite (20, LOW);
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0);
lcd.print("Initializing GPS"); // print a simple message
}
//********************************************************************************************************************************************************************************************
void loop() {
gpsGet();
}
//********************************************************************************************************************************************************************************************
void turnLeft(int speed){
analogWrite(left2, speed);
digitalWrite(left1, LOW);
analogWrite(right1, speed);
digitalWrite(right2, LOW);
}
//******************************
void turnRight(int speed){
analogWrite(left1, speed);
digitalWrite(left2, LOW);
analogWrite(right2, speed);
digitalWrite(right1, LOW);
}
//******************************
void moveForwards(int speed){
analogWrite(right1, speed);
digitalWrite(right2, LOW);
analogWrite(left1, speed);
digitalWrite(left2, LOW);
}
//******************************
void moveBackwards(int speed){
analogWrite(right2, speed);
digitalWrite(right1, LOW);
analogWrite(left2, speed);
digitalWrite(left1, LOW);
}
//******************************
void turn90right(){
turnRight(150);
delay(985);
}
void turn90left(){
turnLeft(150);
delay(985);
}
//******************************
void haltyoudemon(){
digitalWrite(right2, LOW);
digitalWrite(right1, LOW);
digitalWrite(left2, LOW);
digitalWrite(left1, LOW);
}
//******************************
void gpsGet(){
while (Serial1.available()> 0){
if(Mark_Start){
data=reader();
Serial.println(data);
if(data.equals("GPGGA")){
//Serial.println(1);
GGAUTCtime=reader();
GGAlatitude=reader();
GGAlatitude+=reader();
GGAlongitude=reader();
GGAlongitude+=reader();
GPStatus=reader();
SatelliteNum=reader();
HDOPfactor=reader();
Height=reader();
Mark_Start=false;
valid=true;
data="";
}
else if(data.equals("GPGSA")){
Serial.println(2);
Mark_Start=false;
data="";
}
else if(data.equals("GPGSV")){
Serial.println(3);
Mark_Start=false;
data="";
}
else if(data.equals("GPRMC")){
//Serial.println(4);
RMCUTCtime=reader();
PositionValid=reader();
RMClatitude=reader();
RMClatitude+=reader();
RMClongitude=reader();
RMClongitude+=reader();
Speed=reader();
Direction=reader();
Date=reader();
Declination=reader();
Declination+=reader();
Mode=reader();
valid=true;
Mark_Start=false;
data="";
}
else if(data.equals("GPVTG")){
Serial.println(5);
Mark_Start=false;
data="";
}
else{
Serial.println(6);
Mark_Start=false;
data="";
}
}
if(valid){
if(PositionValid=="A"){
Serial.println("Position Valid");
}
else{
Serial.println("Your position is not valid.");
}
lcd.clear();
CoordNum();
Serial.print("Date:");
Serial.println(Date);
Serial.print("UTCtime:");
Serial.print(RMCUTCtime);
Serial.print(" ");
Serial.println(GGAUTCtime);
Serial.print("Latitude:");
Serial.print(RMClatitude);
lcd.setCursor(0,0);
lcd.print(RMClatitude);
Serial.print(" ");
Serial.println(GGAlatitude);
Serial.print("Longitude:");
Serial.print(RMClongitude);
lcd.setCursor(0,1);
lcd.print(RMClongitude);
Serial.print(" ");
Serial.println(GGAlongitude);
Serial.print("GPStatus:");
Serial.println(GPStatus);
Serial.print("SatelliteNum:");
Serial.println(SatelliteNum);
Serial.print("HDOPfactor:");
Serial.println(HDOPfactor);
Serial.print("Height:");
Serial.println(Height);
Serial.print("Speed:");
Serial.println(Speed);
Serial.print("Direction:");
Serial.println(Direction);
Serial.print("Declination:");
Serial.println(Declination);
Serial.print("Mode:");
Serial.println(Mode);
valid=false;
}
if(Serial1.find("$")){
Serial.println("capture");
Mark_Start=true;
}
}
}
String reader(){
String value="";
int temp;
startover:
while (Serial1.available() > 0){
delay(2);
temp=Serial1.read();
if((temp==',')||(temp=='*')){
if(value.length()){
//Serial.println("meaningful message");
return value;
}
else {
//Serial.println("empty");
return "";
}
}
else if(temp=='$'){
//Serial.println("failure");
Mark_Start=false;
}
else{
//Serial.println("add");
value+=char(temp);
}
}
while (!(Serial1.available()>0)){
}
goto startover;
}
//******************************
void CoordNum(){
RMClatitude.remove(RMClatitude.length()-1);
RMClongitude.remove(RMClongitude.length()-1);
latitude = RMClatitude.toInt();
longitude = RMClongitude.toInt();
}
Monthly Archives: May 2018
Note Frequency Chart
Drawing Heart in Processing
void setup(){
size(100,100);
background(255);
}
void draw(){
smooth();
noStroke();
fill(255,0,0);
beginShape();
vertex(50, 15);
bezierVertex(50, -5, 90, 5, 50, 40);
vertex(50, 15);
bezierVertex(50, -5, 10, 5, 50, 40);
endShape();
}
Python Rolling the Dice
import random
min = 1
max = 6
roll = "yes"
while roll == "yes" or roll == "y":
print "Rolling the dice..."
print "The values are...."
print random.randint(min, max)
print random.randint(min, max)
roll = raw_input("Roll the dice again?")
Centers of Triangles
Geometry Definitions, Postulates, and Theorems
Transversals of Parallel Lines
Python Guessing Game
#importing the time module
import time
#welcoming the user
name = raw_input("What is your name? ")
print "Hello, " + name, "Time to play the guessing game!"
print " "
#wait for 1 second
time.sleep(1)
print "Start guessing..."
time.sleep(0.5)
#here we set the secret
word = "secret"
#creates an variable with an empty value
guesses = ''
#determine the number of turns
turns = 10
# Create a while loop
#check if the turns are more than zero
while turns > 0:
# make a counter that starts with zero
failed = 0
# for every character in secret_word
for char in word:
# see if the character is in the players guess
if char in guesses:
# print then out the character
print char,
else:
# if not found, print a dash
print "_",
# and increase the failed counter with one
failed += 1
# if failed is equal to zero
# print You Won
if failed == 0:
print "You won"
# exit the script
break
print
# ask the user go guess a character
guess = raw_input("guess a character:")
# set the players guess to guesses
guesses += guess
# if the guess is not found in the secret word
if guess not in word:
# turns counter decreases with 1 (now 9)
turns -= 1
# print wrong
print "Wrong"
# how many turns are left
print "You have", + turns, 'more guesses'
# if the turns are equal to zero
if turns == 0:
# print "You Loose"
print "You Loose"
L293N Arduino Motor Control Code – Non-Variable Speed
//L293D
//Motor A
const int motorPin1 = 9; // Pin 14 of L293
const int motorPin2 = 10; // Pin 10 of L293
//Motor B
const int motorPin3 = 6; // Pin 7 of L293
const int motorPin4 = 5; // Pin 2 of L293
//This will run only one time.
void setup(){
//Set pins as outputs
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
//Motor Control - Motor A: motorPin1,motorpin2 &amp; Motor B: motorpin3,motorpin4
//This code will turn Motor A clockwise for 2 sec.
analogWrite(motorPin1, 180);
analogWrite(motorPin2, 0);
analogWrite(motorPin3, 180);
analogWrite(motorPin4, 0);
delay(5000);
//This code will turn Motor A counter-clockwise for 2 sec.
analogWrite(motorPin1, 0);
analogWrite(motorPin2, 180);
analogWrite(motorPin3, 0);
analogWrite(motorPin4, 180);
delay(5000);
//This code will turn Motor B clockwise for 2 sec.
analogWrite(motorPin1, 0);
analogWrite(motorPin2, 180);
analogWrite(motorPin3, 180);
analogWrite(motorPin4, 0);
delay(1000);
//This code will turn Motor B counter-clockwise for 2 sec.
analogWrite(motorPin1, 180);
analogWrite(motorPin2, 0);
analogWrite(motorPin3, 0);
analogWrite(motorPin4, 180);
delay(1000);
//And this code will stop motors
analogWrite(motorPin1, 0);
analogWrite(motorPin2, 0);
analogWrite(motorPin3, 0);
analogWrite(motorPin4, 0);
}
void loop(){
}
L298N Arduino Control Code 2 Non-Variable Speed
/* Arduino DC Motor Control - PWM | H-Bridge | L298N - Example 01
by Dejan Nedelkovski, www.HowToMechatronics.com
*/
#define enA 9
#define in1 6
#define in2 7
#define button 4
int rotDirection = 0;
int pressed = false;
void setup() {
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(button, INPUT);
// Set initial rotation direction
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
}
void loop() {
int potValue = analogRead(A0); // Read potentiometer value
int pwmOutput = map(potValue, 0, 1023, 0 , 255); // Map the potentiometer value from 0 to 255
analogWrite(enA, pwmOutput); // Send PWM signal to L298N Enable pin
// Read button - Debounce
if (digitalRead(button) == true) {
pressed = !pressed;
}
while (digitalRead(button) == true);
delay(20);
// If button is pressed - change rotation direction
if (pressed == true &amp; rotDirection == 0) {
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
rotDirection = 1;
delay(20);
}
// If button is pressed - change rotation direction
if (pressed == false &amp; rotDirection == 1) {
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
rotDirection = 0;
delay(20);
}
}



