Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
StanislavJochman committed Jan 3, 2019
0 parents commit c407941
Show file tree
Hide file tree
Showing 5 changed files with 335 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
= Atmega8_IO_basic Library for robot Cing =

This library allows robot Cing to be programmed easily.

For more information about this library please visit us at
http://robotcing.wz.sk

== License ==

Copyright © 2019 RobotCing Team. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
26 changes: 26 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Created by RobotCing Team
*/
##########################################
# Syntax Coloring Map For Atmega8_IO_basic
##########################################

##########################################
# Datatypes (KEYWORD1)
##########################################
Atmega8_IO_basic KEYWORD1
##########################################
# Methods and Functions (KEYWORD2)
##########################################
Robot KEYWORD2
RunMotor KEYWORD2
ReadLightSensor KEYWORD2
ReadUltrasonicSensor KEYWORD2
ReadShineSensor KEYWORD2
ReadButton KEYWORD2
ReadButtonExternal KEYWORD2
ReadProtentiometerExternal KEYWORD2

##########################################
# Constants (LITERAL1)
##########################################
9 changes: 9 additions & 0 deletions library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=Atmega8_IO_basic
version=3.0.0
author=RobotCing Team
maintainer=RobotCing Team <[email protected]>
sentence=Library for robot Cing with Atmega8.
paragraph=This library simplifies programming of robot Cing.
category=Uncategorized
url=http://robotcing.wz.sk
architectures=*
256 changes: 256 additions & 0 deletions src/Atmega8_IO_basic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
/*
Created by RobotCing Team
*/


//--------------------------------------------
// Library import
//--------------------------------------------
#include "Arduino.h"
#include "Atmega8_IO_basic.h"
//--------------------------------------------
Cing::Cing(){}
//--------------------------------------------
// Motors
//--------------------------------------------
void Cing::RunMotor(String motor,int speed,String mode)
{
#define motorA 12
#define motorB 11
#define INA1 10
#define INA2 9
#define INB1 8
#define INB2 7
pinMode(motorA,OUTPUT);
pinMode(motorB,OUTPUT);
//---------------------
pinMode(INA1,OUTPUT);
pinMode(INA2,OUTPUT);
pinMode(INB1,OUTPUT);
pinMode(INB2,OUTPUT);
if(mode=="digital")
{
int speed_set;
if (speed == 1 || speed == -1)
{
speed_set = HIGH;
}
else if (speed == 0)
{
speed_set = LOW;
}
//--------------------------
// A
//--------------------------
if(motor=="A")
{
if (speed == 1)
{
digitalWrite(INA1,HIGH);
digitalWrite(INA2,LOW);
digitalWrite(motorA,speed_set);
}
else if (speed == -1)
{
digitalWrite(INA1,LOW);
digitalWrite(INA2,HIGH);
digitalWrite(motorA,speed_set);
}
else if (speed == 0)
{
digitalWrite(INA1,LOW);
digitalWrite(INA2,LOW);
digitalWrite(motorA,LOW);
}
}
//--------------------------
// B
//--------------------------
else if(motor=="B")
{
if (speed == 1)
{
digitalWrite(INB1,HIGH);
digitalWrite(INB2,LOW);
digitalWrite(motorB,speed_set);
}
else if (speed == -1)
{
digitalWrite(INB1,LOW);
digitalWrite(INB2,HIGH);
digitalWrite(motorB,speed_set);
}
else if (speed == 0)
{
digitalWrite(INB1,LOW);
digitalWrite(INB2,LOW);
digitalWrite(motorB,LOW);
}
}
//--------------------------
// AB
//--------------------------
else if(motor=="AB")
{
if (speed == 1)
{
digitalWrite(INA1,HIGH);
digitalWrite(INA2,LOW);
digitalWrite(INB1,HIGH);
digitalWrite(INB2,LOW);
digitalWrite(motorA,speed_set);
digitalWrite(motorB,speed_set);
}
else if (speed == -1)
{
digitalWrite(INA1,LOW);
digitalWrite(INA2,HIGH);
digitalWrite(INB1,LOW);
digitalWrite(INB2,HIGH);
digitalWrite(motorA,speed_set);
digitalWrite(motorB,speed_set);
}
else if (speed == 0)
{
digitalWrite(INA1,LOW);
digitalWrite(INA2,LOW);
digitalWrite(INB1,LOW);
digitalWrite(INB2,LOW);
digitalWrite(motorA,LOW);
digitalWrite(motorB,LOW);
}
}
else
{
digitalWrite(motorA,LOW);
digitalWrite(motorB,LOW);
}
}
}
//--------------------------------------------
// Sensors
//--------------------------------------------

//--------------------------------------------
// LightSensor
//--------------------------------------------

int Cing::ReadLightSensor(int sensor,String mode)
{
#define LightSensor1 A2
#define LightSensor2 A3
pinMode(LightSensor1,INPUT);//1
pinMode(LightSensor2,INPUT);//2
if (mode=="analog")
{
if (sensor == 1)
{
int value;
value = map(analogRead(LightSensor1),0,1023,100,0);
return value;
}
else if (sensor == 2)
{
int value;
value = map(analogRead(LightSensor2),0,1023,100,0);
return value;
}
}
else if(mode=="digital")
{
if (sensor == 1)
{
int value;
value = digitalRead(LightSensor1);
return value;
}
else if (sensor == 2)
{
int value;
value = digitalRead(LightSensor2);
return value;
}
else
{
int value;
value = digitalRead(LightSensor1);
return value;
}
}
}
//--------------------------------------------
// UltrasonicSensor
//--------------------------------------------

int Cing::ReadUltrasonicSensor()
{
#define UltrasonicSensor 13
int duration;
int distance;
pinMode(UltrasonicSensor, OUTPUT);
digitalWrite(UltrasonicSensor, LOW);
delayMicroseconds(2);
digitalWrite(UltrasonicSensor, HIGH);
delayMicroseconds(10);
digitalWrite(UltrasonicSensor, LOW);
delayMicroseconds(10);
pinMode(UltrasonicSensor, INPUT);
duration = pulseIn(UltrasonicSensor, HIGH);
distance = duration/58.2;
return distance;
}
//--------------------------------------------
// ShineSensors
//--------------------------------------------
int Cing::ReadShineSensor(int sensor)
{
#define ShineSensor 13
#define LDR_1 A6
#define LDR_2 A7
pinMode(ShineSensor,INPUT);
int shine_value;
if(sensor == 0)
{
int shine_value = map(digitalRead(ShineSensor),0,1,0,100);
return shine_value;
}
else if(sensor == 1)
{
int shine_value = map(analogRead(LDR_1),0,1023,100,0);
return shine_value;
}
else if(sensor == 2)
{
shine_value = map(analogRead(LDR_2),0,1023,100,0);
return shine_value;
}
}
//--------------------------------------------
// Button
//--------------------------------------------
bool Cing::ReadButton()
{
#define Button A6
pinMode(Button,INPUT);
bool button_value = digitalRead(Button);
return button_value;
}
//--------------------------------------------
// ButtonExternal
//--------------------------------------------
bool Cing::ReadButtonExternal()
{
#define button_external 13
pinMode(button_external,INPUT);
bool button_external_value = digitalRead(button_external);
return button_external_value;
}
//--------------------------------------------
// Potentiometer
//--------------------------------------------
int Cing::ReadPotentiometer()
{
#define potentiometer A1
int potentiometer_value = map(analogRead(potentiometer),0,1023,0,100);
return potentiometer_value;
}
26 changes: 26 additions & 0 deletions src/Atmega8_IO_basic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Created by RobotCing Team
*/
#ifndef Atmega8_IO_basic
#define Atmega8_IO_basic
#include "Arduino.h"
//--------------------------------------------
// Creating Class
//--------------------------------------------
class Cing
{
// public variables
public:
//constructor
Cing();
void RunMotor(String motor,int speed= 100,String mode = "digital");
int ReadLightSensor(int sensor = 1,String mode = "digital");
int ReadUltrasonicSensor();
int ReadShineSensor(int sensor = 0);
bool ReadButton();
bool ReadButtonExternal();
int ReadPotentiometer();
// local variables
private:
};
#endif

0 comments on commit c407941

Please sign in to comment.