Skip to content

Instantly share code, notes, and snippets.

View tieubinhco's full-sized avatar
🍉
Coding

Tieu Binh tieubinhco

🍉
Coding
  • A2Technology
  • HCMC
View GitHub Profile
@tieubinhco
tieubinhco / ReadSpeedEncoderMotor_Arduino.ino
Last active December 1, 2020 13:55
Code read speed of dc motor with encoder Arduino (quadrature) output RPM
#include <Encoder.h>
#define IN1 7
#define IN2 8
#define PWM 5
#define EN_A 2
#define EN_B 3
//Declare encoder function
Encoder Enc(EN_A, EN_B);
#include <Encoder.h>
#define IN1 7
#define IN2 8
#define PWM 5
#define EN_A 2
#define EN_B 3
//Declare encoder function
Encoder Enc(EN_A, EN_B);
float read_speed(int select)
{
//read velocity of selected motor
//return velocity in rad/s
const float PI=3.1415926;
const int Encoder_1_round = 44; //define number of pulses in one round of encoder
currentEncoder = Encoder_1.read();
float rot_speed; //rotating speed in rad/s
@tieubinhco
tieubinhco / SemVer.txt
Created September 8, 2020 17:40
SemVer
Semantic Versioning Specification (SemVer)
The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119.
Software using Semantic Versioning MUST declare a public API. This API could be declared in the code itself or exist strictly in documentation. However it is done, it SHOULD be precise and comprehensive.
A normal version number MUST take the form X.Y.Z where X, Y, and Z are non-negative integers, and MUST NOT contain leading zeroes. X is the major version, Y is the minor version, and Z is the patch version. Each element MUST increase numerically. For instance: 1.9.0 -> 1.10.0 -> 1.11.0.
Once a versioned package has been released, the contents of that version MUST NOT be modified. Any modifications MUST be released as a new version.
Major version zero (0.y.z) is for initial development. Anything MAY change at any time. The public API SHOULD NOT be considered stable.
@tieubinhco
tieubinhco / motor_control.cpp
Created September 8, 2020 17:08
Motor control Arduino
void w1(int rotation, int direct)
{
analogWrite(PWM1, rotation);
if (direct == 1)
{
digitalWrite(IN1A, HIGH);
digitalWrite(IN2A, LOW);
}
else if (direct == -1)
{
@tieubinhco
tieubinhco / sign_of.cpp
Created September 8, 2020 16:49
sign function in C++
int sign_of(float x)
{
if (x >= 0)
return 1;
else
return -1;
}
### Keybase proof
I hereby claim:
* I am tieubinhco on github.
* I am tieubinhco (https://keybase.io/tieubinhco) on keybase.
* I have a public key ASAECKCnumGhNDDzmdcEwbAnNyBLODNUDiHFDfh9PU4tGgo
To claim this, I am signing this object:
@tieubinhco
tieubinhco / area of a triangle in C
Created March 11, 2018 18:40
Calculate the area of a triangle in C
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void main()
{
double a,b,c;
printf("Enter triangle lengths a, b, c: \n");
scanf("%lf %lf %lf", &a,&b,&c);
if (a+b<=c || a+c<=b || b+c<=a || a<=0 || b<=0 || c<=0)