Racing Pygame Sample

First, pygame must be installed.
In CMD: pip install pygame

import pygame


pygame.init()


display_width = 800
display_height = 600

gameDisplay = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption('A bit Racey')

black = (0,0,0)
white = (255,255,255)

clock = pygame.time.Clock()
crashed = False
carImg = pygame.image.load('racecar.png')

def car(x,y):
    gameDisplay.blit(carImg, (x,y))

x =  (display_width * 0.45)
y = (display_height * 0.8)

while not crashed:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            crashed = True

    gameDisplay.fill(white)
    car(x,y)

        
    pygame.display.update()
    clock.tick(60)

pygame.quit()
quit()

Source

Pygame Chest Open Sample

First, pygame must be installed.
In CMD: pip install pygame


import pygame

pygame.init()
pygame.display.set_caption('Crash!')
window = pygame.display.set_mode((300, 300))
running = True

# Draw Once
Rectplace = pygame.draw.rect(window, (255, 0, 0),(100, 100, 100, 100))
pygame.display.update()
# Main Loop
while running:
    # Mouse position and button clicking.
    pos = pygame.mouse.get_pos()
    pressed1, pressed2, pressed3 = pygame.mouse.get_pressed()
    # Check if the rect collided with the mouse pos
    # and if the left mouse button was pressed.
    if Rectplace.collidepoint(pos) and pressed1:
        print("You have opened a chest!")
    # Quit pygame.
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

Source

Current Bogie Code *Change Port Definitions*

#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
}
bool clipped = 0;
//********************************************************************************************************************************************************************************************
void loop() {
  gpsBoi();
  clipped = 0;
}
//********************************************************************************************************************************************************************************************
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 halt(){
digitalWrite(right2, LOW);
digitalWrite(right1, LOW);
digitalWrite(left2, LOW);
digitalWrite(left1, LOW);
}
//******************************
void gpsBoi(){
    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");
        lcd.clear();
      }
      else{
        Serial.println("Your position is not valid.");
      }
      //lcd.clear();
      clearCoord();
      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(latitude);
      Serial.print("   ");
      Serial.println(GGAlatitude);
      Serial.print("Longitude:");
      Serial.print(RMClongitude);
      lcd.setCursor(0,1);
      lcd.print(longitude);
      Serial.println("LONGITUDE THE REAL ONE");
      Serial.println(longitude);
      Serial.println("LATITUDE THE REAL ONE");
      Serial.println(latitude);
      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 clearCoord(){
  if(clipped == 0){
    RMClatitude.remove(RMClatitude.length()-1);
    RMClongitude.remove(RMClongitude.length()-1);
    RMClatitude.remove(0,5);
    RMClongitude.remove(0,6);
    latitude = RMClatitude.toInt();
    longitude = RMClongitude.toInt();
  }
  clipped = 1;
  }

Rocker-Bogie GPS and Motor Control Code

#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();
}

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?")