Last active
December 30, 2015 10:59
-
-
Save e-Gizmo/7819632 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////////////////////////// | |
// 2-DIGIT 7-SEGMENT DISPLAY // | |
// FOR eGizmo UNIVERSAL MCU TRAINER // | |
// // | |
// This serves as a sample program for // | |
// 2 digit 7 segment displays wherein // | |
// in counts from 0 to 99 // | |
// // | |
// See manual for pin and segment connections // | |
// // | |
// Codes by: // | |
// eGizmo Mechatronix Central // | |
// Taft, Manila, Philippines // | |
// http://www.egizmo.com // | |
// April 11, 2013 // | |
//////////////////////////////////////////////// | |
#define D1 13 // DIGIT1 display as pin 13 | |
#define D0 12 // DIGIT0 display as pin 12 | |
#define MPX 10 // Delay for Multiplexing (this can only be from 1-10) | |
const int numberPin[7] = {0,1,2,3,4,5,6}; // Sets pins 0-7 as number pins | |
// Segments that make each number | |
const byte numbers[10] = | |
{// abcdefg | |
B1000000, // 0 | |
B1111001, // 1 | |
B0100100, // 2 | |
B0110000, // 3 | |
B0011001, // 4 | |
B0010010, // 5 | |
B0000010, // 6 | |
B1111000, // 7 | |
B0000000, // 8 | |
B0010000 // 9 | |
}; | |
void setup() { | |
for(int i =0; i<=7; i++) | |
{ | |
pinMode(i, OUTPUT); // Sets pins 0-7 as OUTPUT | |
} | |
pinMode(D1, OUTPUT); // Sets DIGIT1 (Pin 13) as OUTPUT | |
pinMode(D0, OUTPUT); // Sets DIGIT0 (Pin 12) as OUTPUT | |
digitalWrite(7,HIGH); // Turns off DP segment, replace HIGH with LOW to enable decimals | |
} | |
void loop() { | |
for (int digit1=0; digit1<=9; digit1++) // Variable for second digit from 0 to 9 | |
{ | |
for (int digit0=0; digit0<=9; digit0++) // Variable for first digit from 0 to 9 | |
{ | |
unsigned long startTime = millis(); | |
for (unsigned long elapsed = 0; elapsed <= 1000; elapsed = millis() - startTime) // This is wherein one sets the delay for each digit 1000ms or 1s as default | |
{ | |
lightDigit1(numbers[digit1]); // Quickly turns off DIGIT1 so that data is stored | |
delay(MPX); | |
lightDigit0(numbers[digit0]); // Quickly turns off DIGIT0 so that data is stored | |
delay(MPX); | |
} | |
} | |
} | |
} | |
// Function for writing segments | |
void numberWrite(byte number) | |
{ | |
for (int i = 0; i < 7; i++) | |
{ | |
int bit = bitRead(number, i); | |
digitalWrite(numberPin[i], bit); | |
} | |
} | |
// Functions for Multiplexing | |
void lightDigit1(byte number) | |
{ | |
digitalWrite(D1, LOW); // Turns on display for second digit | |
digitalWrite(D0, HIGH); // Turns off display for first digit | |
numberWrite(number); | |
} | |
void lightDigit0(byte number) | |
{ | |
digitalWrite(D1, HIGH); // Turns off display for second digit | |
digitalWrite(D0, LOW); // Turns on display for first digit | |
numberWrite(number); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///////////////////////////////////// | |
// Analog voltage source // | |
// eGizmo Universal MCU Trainer // | |
// // | |
// Reads analog voltage from // | |
// three voltage sources provided // | |
// in the trainer. Max of 5V // | |
// // | |
// Simply connect VR1, VR2 and VR3 // | |
// to A0, A1 and A2 respectively // | |
// // | |
// Codes by: // | |
// Dan // | |
// eGizmo Mechatronix Central // | |
// Taft, Manila, Philippines // | |
// http://www.egizmo.com // | |
///////////////////////////////////// | |
const int D = 50; | |
// Delay for voltage reading. Maintain a low value so that | |
// voltage can be controlled easier. | |
void setup() | |
{ | |
Serial.begin(9600); // Begin serial communication | |
} | |
void loop() { | |
int VR1 = analogRead(A0); | |
int VR2 = analogRead(A1); | |
int VR3 = analogRead(A2); | |
float V1 = VR1 * (5.0 / 1023.0); // Formula for voltage reading 1 | |
float V2 = VR2 * (5.0 / 1023.0); // Formula for voltage reading 2 | |
float V3 = VR3 * (5.0 / 1023.0); // Formula for voltage reading 3 | |
Serial.print(V1); Serial.print(" "); Serial.print(V2); Serial.print(" "); Serial.print(V3); Serial.print(" "); | |
Serial.print("\n"); | |
delay(D); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///////////////////////////////////// | |
// Analog voltage source w/ LCD // | |
// eGizmo Universal MCU Trainer // | |
// // | |
// Reads analog voltage from // | |
// three voltage sources provided // | |
// in the trainer. Max of 5V // | |
// // | |
// Simply connect VR1, VR2 and VR3 // | |
// to A0, A1 and A2 respectively // | |
// // | |
// See circuit diagram on the same // | |
// folder for other connections // | |
// // | |
// Codes by: // | |
// eGizmo Mechatronix Central // | |
// Taft, Manila, Philippines // | |
// http://www.egizmo.com // | |
///////////////////////////////////// | |
#include<LiquidCrystal.h> | |
LiquidCrystal lcd(13,12,4,5,6,7); | |
// LCD Pins Connection: | |
// NOTE: The reference for this connections is | |
// according to JP1 of the MCU Trainer. This is | |
// different when using a separate LCD display | |
// | |
// LCD RS (Pin 1) to Arduino pin 13 | |
// LCD R/W (Pin2) to GND | |
// LCD EN (Pin 3) to Arduino pin 12 | |
// LCD D4 (Pin 8) to Arduino pin 4 | |
// LCD D5 (Pin 9) to Arduino pin 5 | |
// LCD D6 (Pin 10) to Arduino pin 6 | |
// LCD D7 (Pin 11) to Arduino pin 7 | |
#define D 50 | |
// Delay for voltage reading. Maintain a low value so that | |
// voltage can be controlled easier. | |
#define BUZZER 9 | |
// Connect buzzer to digital pin 9 | |
void setup() | |
{ | |
Serial.begin(9600); // Begin serial communication (optional) | |
lcd.begin(16,2); | |
} | |
void loop() { | |
int VR1 = analogRead(A0); | |
int VR2 = analogRead(A1); | |
int VR3 = analogRead(A2); | |
float VP1 = VR1 * (5.0 / 1023.0); // Formula for voltage reading 1 | |
float VP2 = VR2 * (5.0 / 1023.0); // Formula for voltage reading 2 | |
float VP3 = VR3 * (5.0 / 1023.0); // Formula for voltage reading 3 | |
// Optional serial reading: | |
Serial.print(VP1); Serial.print(" "); Serial.print(VP2); Serial.print(" "); Serial.print(VP3); Serial.print(" "); | |
Serial.print("\n"); | |
lcd.setCursor(0,1); | |
lcd.print(VP1); | |
lcd.setCursor(5,1); | |
lcd.print(VP2); | |
lcd.setCursor(10,1); | |
lcd.print(VP3); | |
lcd.setCursor(0,0); | |
lcd.print("Voltage Monitor"); | |
// Optional 5v indicator. If necessary, connect buzzer to | |
// pin 9 of the MCU | |
if(VP1==5) | |
{ | |
tone(BUZZER,1000,100); | |
} | |
if(VP2==5) | |
{ | |
tone(BUZZER,1000,100); | |
} | |
if(VP3==5) | |
{ | |
tone(BUZZER,1000,100); | |
} | |
delay(D); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////////////// | |
// LCD Display #2 (MCU TRAINER) // | |
// // | |
// This sample program enables // | |
// the user to use the auto // | |
// scroll function of the lcd // | |
// display. // | |
// // | |
// Codes by: // | |
// eGizmo Mechatronix Central // | |
// Taft, Manila, Philippines // | |
// http://www.egizmo.com // | |
//////////////////////////////////// | |
#include <LiquidCrystal.h> | |
// Includes liquid crystal library | |
LiquidCrystal lcd(13,12,14,15,16,17); | |
// LCD Pins Connection: | |
// NOTE: The reference for this connections is | |
// according to JP1 of the MCU Trainer. This is | |
// different when using a separate LCD display | |
// | |
// LCD RS (Pin 1) to Arduino pin 13 | |
// LCD R/W (Pin2) to GND | |
// LCD EN (Pin 3) to Arduino pin 12 | |
// LCD D4 (Pin 8) to Arduino pin 14 | |
// LCD D5 (Pin 9) to Arduino pin 15 | |
// LCD D6 (Pin 10) to Arduino pin 16 | |
// LCD D7 (Pin 11) to Arduino pin 17 | |
char characters[] = {'A','R','D','U','I','N','O'}; | |
// An array for defining the characters of your message | |
int SPEED = 200; | |
// Adjsutable speed | |
void setup() | |
{ | |
lcd.begin(16,2); | |
// Sets lcd number of rows and columns | |
} | |
void loop() | |
{ | |
lcd.setCursor(0,0); // Sets lcd cursor | |
for(int letter = 0; letter<=6; letter++) | |
{ | |
lcd.print(characters[letter]); // Prints out the letters one by one | |
delay(SPEED); // How quick the letters will show up | |
} | |
lcd.setCursor(16,1); // Sets lcd crusor to next line | |
lcd.autoscroll(); // Enables autoscroll | |
for(int letter = 0; letter<=6; letter++) | |
{ | |
lcd.print(characters[letter]); // Prints out the letters one by one | |
delay(SPEED); // How quick the letters will show up | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////////////// | |
// Digital To Analog Converter // | |
// MCU Trainer using MAX5382 // | |
// // | |
// This program allows the user // | |
// to convert a digital input // | |
// from the MCU to I2c device // | |
// then converts it into an // | |
// analog reading. // | |
// // | |
// Pin assignments: // | |
// SCL to Pin A5 // | |
// SDA to Pin A4 // | |
// Analog output of DAC to A0 // | |
// // | |
// Codes by: // | |
// eGizmo Mechatronix Central // | |
// Taft, Manila, Philippines // | |
// http://www.egizmo.com // | |
// April 18, 2013 // | |
//////////////////////////////////// | |
// NOTE: | |
// If you are having problem finding the | |
// address of your I2c device. Uncomment | |
// the following codes for I2c library and | |
// comment the wire codes using /* */ | |
// then upload. You should see the address | |
// of your device by using the I2c.scan() function. | |
/* | |
/////////////////////// I2c //////////////////////// | |
#include <I2C.h> | |
#define MAX5382 0x30 // I2c device address | |
void setup() | |
{ | |
I2c.begin(); | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
I2c.scan(); | |
} | |
//////////////////////////////////////////////////// | |
*/ | |
//////////////////////// WIRE ////////////////////// | |
#include <Wire.h> | |
#include <LiquidCrystal.h> | |
#define MAX5382 0x30 // I2c device address | |
LiquidCrystal lcd(13,12,8,9,10,11); | |
// LCD Pins Connection: | |
// NOTE: The reference for this connections is | |
// according to JP1 of the MCU Trainer. This is | |
// different when using a separate LCD display | |
// | |
// LCD RS (Pin 1) to Arduino pin 13 | |
// LCD R/W (Pin2) to GND | |
// LCD EN (Pin 3) to Arduino pin 12 | |
// LCD D4 (Pin 8) to Arduino pin 8 | |
// LCD D5 (Pin 9) to Arduino pin 9 | |
// LCD D6 (Pin 10) to Arduino pin 10 | |
// LCD D7 (Pin 11) to Arduino pin 11 | |
int intensity = 0; | |
void setup() | |
{ | |
Wire.begin(); | |
Serial.begin(9600); | |
lcd.begin(16,2); | |
lcd.setCursor(0,0); | |
lcd.print(" eGizmo "); | |
lcd.setCursor(0,1); | |
lcd.print(" DAC "); | |
delay(2000); | |
lcd.clear(); | |
} | |
void loop() | |
{ | |
for(intensity = 256; intensity>=0; intensity--) | |
{ | |
// The intensity is just an assumption of the | |
// LED's brightness | |
Wire.beginTransmission(MAX5382); | |
Wire.write(intensity); | |
Wire.endTransmission(); | |
int wireReading = analogRead(A0); | |
float voltage = wireReading * (5.0 / 1023.0); | |
// Standard code for reading voltage through | |
// the analog pin of arduino. | |
lcd.setCursor(0,0); | |
lcd.print("Voltage:"); | |
lcd.setCursor(12,0); | |
lcd.print(voltage); | |
lcd.setCursor(0,1); | |
lcd.print("Intensity:"); | |
lcd.setCursor(13,1); | |
lcd.print(intensity); | |
delay(50); // Set delay for fading effect | |
} | |
} | |
////////////////////////////////////////////////////// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////////////// | |
// Digital To Analog Converter // | |
// MCU Trainer using MAX5382 // | |
// // | |
// This program allows the user // | |
// to convert a digital input // | |
// from the MCU to I2c device // | |
// then converts it into an // | |
// analog reading. // | |
// // | |
// Pin assignments: // | |
// SCL to Pin A5 // | |
// SDA to Pin A4 // | |
// Analog output of DAC to A0 // | |
// // | |
// Codes by: // | |
// eGizmo Mechatronix Central // | |
// Taft, Manila, Philippines // | |
// http://www.egizmo.com // | |
// April 18, 2013 // | |
//////////////////////////////////// | |
// NOTE: | |
// If you are having problem finding the | |
// address of your I2c device. Uncomment | |
// the following codes for I2c library and | |
// comment the wire codes using /* */ | |
// then upload. You should see the address | |
// of your device by using the I2c.scan() function. | |
/* | |
/////////////////////// I2c //////////////////////// | |
#include <I2C.h> | |
#define MAX5382 0x30 // I2c device address | |
void setup() | |
{ | |
I2c.begin(); | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
I2c.scan(); | |
} | |
//////////////////////////////////////////////////// | |
*/ | |
//////////////////////// WIRE ////////////////////// | |
#include <Wire.h> | |
#define MAX5382 0x30 // I2c device address | |
int intensity = 0; | |
void setup() | |
{ | |
Wire.begin(); | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
for(intensity = 256; intensity>=0; intensity--) | |
{ | |
Wire.beginTransmission(MAX5382); | |
Wire.write(intensity); | |
Wire.endTransmission(); | |
int wireReading = analogRead(A0); | |
float voltage = wireReading * (5.0 / 1023.0); | |
// Standard code for reading voltage through | |
// the analog pin of arduino. | |
Serial.println(voltage); | |
Serial.println(intensity); | |
delay(50); | |
} | |
} | |
////////////////////////////////////////////////////// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////////////////////////// | |
// 4x3 Switch Matrix + LCD Display + Buzzer // | |
// eGizmo Universal MCU Trainer // | |
// // | |
// This sample program makes use // | |
// of a 4x3 Switch Matrix as keypad // | |
// and LCD Display as read out // | |
// device. Together, this program // | |
// makes a dialer. // | |
// // | |
// Codes by: // | |
// eGizmo Mechatronix Central // | |
// Taft, Manila, Philippines // | |
// http://www.egizmo.com // | |
// April 12, 2013 // | |
//////////////////////////////////////////////// | |
// Activates LCD Library | |
#include<LiquidCrystal.h> | |
LiquidCrystal lcd(13,12,14,15,16,17); | |
// LCD Pins Connection: | |
// NOTE: The reference for this connections is | |
// according to JP1 of the MCU Trainer. This is | |
// different when using a separate LCD display | |
// | |
// LCD RS (Pin 1) to Arduino pin 13 | |
// LCD R/W (Pin2) to GND | |
// LCD EN (Pin 3) to Arduino pin 12 | |
// LCD D4 (Pin 8) to Arduino pin 14 | |
// LCD D5 (Pin 9) to Arduino pin 15 | |
// LCD D6 (Pin 10) to Arduino pin 16 | |
// LCD D7 (Pin 11) to Arduino pin 17 | |
const int numRows = 4; // number of rows in the keypad | |
const int numCols = 3; // number of columns | |
const int debounceTime = 20; // number of milliseconds for switch to be stable | |
// keymap defines the character returned when the corresponding key is pressed | |
const char keymap[numRows][numCols] = { | |
{ '1', '2', '3' } , | |
{ '4', '5', '6' } , | |
{ '7', '8', '9' } , | |
{ '*', '0', '#' } | |
}; | |
// this array determines the pins used for rows and columns | |
const int rowPins[numRows] = { 7, 2, 3, 6 }; // Rows 0 through 3 | |
const int colPins[numCols] = { 5, 8, 4 }; // Columns 0 through 2 | |
// Optional buzzer: | |
const int BUZZER = 9; | |
const int DUR = 100; // Duration for each dial | |
void setup() | |
{ | |
// Serial.begin(9600); // Begins serial communication | |
lcd.begin(16,2); // Sets LCD rows and columns | |
for (int row = 0; row < numRows; row++) | |
{ | |
pinMode(rowPins[row],INPUT); // Set row pins as input | |
digitalWrite(rowPins[row],HIGH); | |
} | |
for (int column = 0; column < numCols; column++) | |
{ | |
pinMode(colPins[column],OUTPUT); // Set column pins as outputs | |
// for writing | |
digitalWrite(colPins[column],HIGH); | |
} | |
pinMode(BUZZER,OUTPUT); | |
} | |
void loop() | |
{ | |
char key = getKey(); | |
if( key != 0) | |
{ | |
// Serial.println(key); | |
lcd.print(key); | |
if(key==keymap[0][0]) | |
{ | |
tone(BUZZER,100,DUR); | |
} | |
if(key==keymap[0][1]) | |
{ | |
tone(BUZZER,150,DUR); | |
} | |
if(key==keymap[0][2]) | |
{ | |
tone(BUZZER,200,DUR); | |
} | |
if(key==keymap[1][0]) | |
{ | |
tone(BUZZER,250,DUR); | |
} | |
if(key==keymap[1][1]) | |
{ | |
tone(BUZZER,300,DUR); | |
} | |
if(key==keymap[1][2]) | |
{ | |
tone(BUZZER,350,DUR); | |
} | |
if(key==keymap[2][0]) | |
{ | |
tone(BUZZER,400,DUR); | |
} | |
if(key==keymap[2][1]) | |
{ | |
tone(BUZZER,450,DUR); | |
} | |
if(key==keymap[2][2]) | |
{ | |
tone(BUZZER,500,DUR); | |
} | |
if(key==keymap[3][0]) | |
{ | |
tone(BUZZER,550,DUR); | |
} | |
if(key==keymap[3][1]) | |
{ | |
tone(BUZZER,600,DUR); | |
} | |
if(key==keymap[3][2]) | |
{ | |
tone(BUZZER,650,DUR); | |
} | |
} | |
} | |
// Function for getting which key is pressed | |
char getKey() | |
{ | |
char key = 0; // 0 indicates no key pressed | |
for(int column = 0; column < numCols; column++) | |
{ | |
digitalWrite(colPins[column],LOW); | |
for(int row = 0; row < numRows; row++) | |
{ | |
if(digitalRead(rowPins[row]) == LOW) | |
{ | |
delay(debounceTime); // Debounce | |
while(digitalRead(rowPins[row]) == LOW); | |
key = keymap[row][column]; // Stores value of key pressed | |
} | |
} | |
digitalWrite(colPins[column],HIGH); | |
} | |
return key; // Returns key value | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///////////////////////////////////////////////////////////////////////// | |
// Input Expander Module // | |
// for MCU Trainer // | |
// // | |
// This sample program makes the module a binary counter. // | |
// A sample circuit is shown in this folder of how // | |
// the input expander may be tested independently without // | |
// an output expander module. // | |
// // | |
// This test program checks the functionality of the input expander // | |
// module using the software's serial monitor and LED indicators. // | |
// // | |
// JP2 pin assignments: // | |
// Dout on digital pin 11 // | |
// Clk on digital pin 12 // | |
// Str on digital pin 13 // | |
// // | |
// Codes by: // | |
// eGizmo Mechatronix Central // | |
// Manila, Philippines // | |
// April 4, 2013 // | |
// // | |
///////////////////////////////////////////////////////////////////////// | |
// constants won't change. They're used here to | |
// set pin numbers: | |
const int INCLK = 12; // input expander CLK pin | |
const int DIN = 11; // input expander DOUT pin | |
const int INSTR = 13; // input expander STR pin | |
const int OUTCLK = A2; // output expander CLK pin | |
const int DOUT = A1; // output expander DIN pin | |
const int OUTSTR = A0; // output expander STR pin | |
// Set delay, bytes, counter, and mask. | |
int d = 100; | |
byte byte1; | |
byte counter; | |
byte mask; | |
void setup() | |
{ | |
// Initialize serial monitor with 9600 baud. | |
Serial.begin(9600); | |
// Set pins to output i stands for increment. | |
pinMode(INCLK, OUTPUT); // Set Clock in as output | |
pinMode(DIN, INPUT); // Set Data in as input | |
pinMode(INSTR, OUTPUT); // Set Strobe in as output | |
pinMode(OUTCLK, OUTPUT); // Set Clock out as output | |
pinMode(DOUT, OUTPUT); // Set Data out as output | |
pinMode(OUTSTR, OUTPUT); // Set Strobe out as output | |
} | |
// Set clock in cycle | |
void CLKIN(){ | |
digitalWrite(INCLK, HIGH); | |
digitalWrite(INCLK, LOW); | |
} | |
// Set clock out cycle | |
void CLKOUT(){ | |
digitalWrite(OUTCLK, HIGH); | |
digitalWrite(OUTCLK, LOW); | |
} | |
// Set strobe in cycle | |
void STRIN(){ | |
digitalWrite(INSTR, HIGH); | |
digitalWrite(INSTR, LOW); | |
} | |
// Set strobe out cycle | |
void STROUT(){ | |
digitalWrite(INSTR, HIGH); | |
digitalWrite(INSTR, LOW); | |
} | |
// Set LED outputs | |
void out_LEDs() | |
{ | |
for(mask=1; mask>0;) | |
{ | |
if(byte1 & mask) | |
digitalWrite(DOUT, HIGH); | |
else | |
digitalWrite(DOUT, LOW); | |
CLKOUT(); | |
mask = mask << 1; | |
} | |
STROUT(); | |
} | |
byte read_LEDs() | |
{ | |
byte byte1 = 0; | |
digitalWrite(INSTR, LOW); | |
CLKIN(); | |
digitalWrite(INSTR, HIGH); | |
for(mask=1; mask>0;) | |
{ | |
if(digitalRead(DIN) == HIGH) | |
byte1 |= mask; | |
CLKIN(); | |
mask = mask << 1; | |
} | |
return byte1; // Returns the value | |
} | |
void loop() | |
{ | |
byte reading = read_LEDs(); | |
// Set reading as the variable for LED output | |
Serial.println(reading); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////////////////////////// | |
// LED MONITOR // | |
// FOR eGizmo UNIVERSAL MCU TRAINER // | |
// // | |
// This serves as a sample program for // | |
// an LED monitor showing a on off sequence. // | |
// // | |
// See manual for pin assignments and sample // | |
// circuit diagram // | |
// // | |
// Codes by: // | |
// eGizmo Mechatronix Central // | |
// Taft, Manila, Philippines // | |
// http://www.egizmo.com // | |
// April 11, 2013 // | |
//////////////////////////////////////////////// | |
int DEL1 = 100; // Adjust this delay for separating functions | |
int DEL2 = 100; // Adjust this delay for individual delay of turning on/off the LEDs | |
int LED_NUMBER[] = {0,1,2,3,4,5,6,7}; | |
void setup() | |
{ | |
for(int i =0; i<=7; i++) | |
{ | |
pinMode(LED_NUMBER[i],OUTPUT); // Sets all the LED pins as OUTPUT | |
} | |
} | |
void loop() | |
{ | |
ASCENDONOFF(); | |
delay(DEL1); | |
DESCENDONOFF(); | |
delay(DEL1); | |
} | |
// Turns on and off the LEDs in ascending order | |
void ASCENDONOFF() | |
{ | |
for(int i=0; i<=7; i++) | |
{ | |
digitalWrite(LED_NUMBER[i],HIGH); // Turns on the LEDs | |
delay(DEL2); | |
digitalWrite(LED_NUMBER[i],LOW); // Turns off the LEDs | |
delay(DEL2); | |
} | |
} | |
// Turns on and off the LEDs in descending order | |
void DESCENDONOFF() | |
{ | |
for(int i=7; i>=0; i--) | |
{ | |
digitalWrite(LED_NUMBER[i],HIGH); // Turns on the LEDs | |
delay(DEL2); | |
digitalWrite(LED_NUMBER[i],LOW); // Turns off the LEDs | |
delay(DEL2); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////////////////////////////////////////////////////////////// // | |
// Output Expander Module for eGizmo Universal MCU Trainer // | |
// // | |
// This program converts a serial into a parallel output with 8 output ports per board. // | |
// Each output ports has LED state indicators. // | |
// +3.3V or +5V of the microcontroller may be used. // | |
// This module is usually used with an input expander module. // | |
// // | |
// Pin assignments: // | |
// Din on digital pin 11 // | |
// Clk on digital pin 12 // | |
// Str on digital pin 13 // | |
// // | |
// Connect the outputs of the MCU trainer to the headers of the LED Monitor. // | |
// 0 on D0... respectively. // | |
// // | |
// Codes by: // | |
// eGizmo Mechatronix Central // | |
// Manila, Philippines // | |
// April 3, 2013 // | |
// // | |
// // | |
////////////////////////////////////////////////////////////////////////////////////////// | |
// Constants | |
const int StrIN = 13; | |
const int ClkIN = 12; | |
const int DataIN = 11; | |
void setup() | |
{ | |
pinMode(DataIN, OUTPUT); // Pin 8 as output | |
pinMode(ClkIN, OUTPUT); // Pin 9 as output | |
pinMode(StrIN, OUTPUT); // Pin 10 as output | |
} | |
void loop() | |
{ | |
for(int i = 0; i<=256; i++) | |
{ | |
shiftOut(i); | |
// Set cycle for strobe in | |
digitalWrite(StrIN, HIGH); | |
digitalWrite(StrIN,LOW); | |
delay(500); | |
} | |
} | |
void shiftOut(byte DataOUT) // Sets a byte called DataOUT | |
{ | |
boolean state; | |
// Sets the cycle for data in and clock in | |
digitalWrite(DataIN, LOW); | |
digitalWrite(ClkIN, LOW); | |
for (int i=0; i<=7; i++) | |
// This is set for 8bit binary. | |
{ | |
digitalWrite(ClkIN, LOW); | |
if (DataOUT&(1<<i)) | |
{ | |
state = HIGH; | |
} | |
else | |
{ | |
state = LOW; | |
} | |
digitalWrite(DataIN, state); | |
digitalWrite(ClkIN, HIGH); | |
} | |
digitalWrite(ClkIN,LOW); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************************************* | |
* Public Constants | |
*************************************************/ | |
#define NOTE_B0 31 | |
#define NOTE_C1 33 | |
#define NOTE_CS1 35 | |
#define NOTE_D1 37 | |
#define NOTE_DS1 39 | |
#define NOTE_E1 41 | |
#define NOTE_F1 44 | |
#define NOTE_FS1 46 | |
#define NOTE_G1 49 | |
#define NOTE_GS1 52 | |
#define NOTE_A1 55 | |
#define NOTE_AS1 58 | |
#define NOTE_B1 62 | |
#define NOTE_C2 65 | |
#define NOTE_CS2 69 | |
#define NOTE_D2 73 | |
#define NOTE_DS2 78 | |
#define NOTE_E2 82 | |
#define NOTE_F2 87 | |
#define NOTE_FS2 93 | |
#define NOTE_G2 98 | |
#define NOTE_GS2 104 | |
#define NOTE_A2 110 | |
#define NOTE_AS2 117 | |
#define NOTE_B2 123 | |
#define NOTE_C3 131 | |
#define NOTE_CS3 139 | |
#define NOTE_D3 147 | |
#define NOTE_DS3 156 | |
#define NOTE_E3 165 | |
#define NOTE_F3 175 | |
#define NOTE_FS3 185 | |
#define NOTE_G3 196 | |
#define NOTE_GS3 208 | |
#define NOTE_A3 220 | |
#define NOTE_AS3 233 | |
#define NOTE_B3 247 | |
#define NOTE_C4 262 | |
#define NOTE_CS4 277 | |
#define NOTE_D4 294 | |
#define NOTE_DS4 311 | |
#define NOTE_E4 330 | |
#define NOTE_F4 349 | |
#define NOTE_FS4 370 | |
#define NOTE_G4 392 | |
#define NOTE_GS4 415 | |
#define NOTE_A4 440 | |
#define NOTE_AS4 466 | |
#define NOTE_B4 494 | |
#define NOTE_C5 523 | |
#define NOTE_CS5 554 | |
#define NOTE_D5 587 | |
#define NOTE_DS5 622 | |
#define NOTE_E5 659 | |
#define NOTE_F5 698 | |
#define NOTE_FS5 740 | |
#define NOTE_G5 784 | |
#define NOTE_GS5 831 | |
#define NOTE_A5 880 | |
#define NOTE_AS5 932 | |
#define NOTE_B5 988 | |
#define NOTE_C6 1047 | |
#define NOTE_CS6 1109 | |
#define NOTE_D6 1175 | |
#define NOTE_DS6 1245 | |
#define NOTE_E6 1319 | |
#define NOTE_F6 1397 | |
#define NOTE_FS6 1480 | |
#define NOTE_G6 1568 | |
#define NOTE_GS6 1661 | |
#define NOTE_A6 1760 | |
#define NOTE_AS6 1865 | |
#define NOTE_B6 1976 | |
#define NOTE_C7 2093 | |
#define NOTE_CS7 2217 | |
#define NOTE_D7 2349 | |
#define NOTE_DS7 2489 | |
#define NOTE_E7 2637 | |
#define NOTE_F7 2794 | |
#define NOTE_FS7 2960 | |
#define NOTE_G7 3136 | |
#define NOTE_GS7 3322 | |
#define NOTE_A7 3520 | |
#define NOTE_AS7 3729 | |
#define NOTE_B7 3951 | |
#define NOTE_C8 4186 | |
#define NOTE_CS8 4435 | |
#define NOTE_D8 4699 | |
#define NOTE_DS8 4978 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////////////////// | |
// Rotary Encoder + LCD Display // | |
// with Frequency display // | |
// eGizmo Universal MCU Trainer // | |
// // | |
// This sample program makes use // | |
// of a rotary encoder with a buzzer // | |
// that outputs the frequency // | |
// received by changing encoder // | |
// position. // | |
// // | |
// Codes by: // | |
// eGizmo Mechatronix Central // | |
// Taft, Manila, Philippines // | |
// http://www.egizmo.com // | |
// April 13, 2013 // | |
//////////////////////////////////////// | |
// Activate liquid crystal library | |
#include<LiquidCrystal.h> | |
#define e_A 5 // Connect A of rotary encoder to pin 5 | |
#define e_B 6 // Connect B of rotary encoder to pin 6 | |
#define SWITCH 7 // Connect S3 of rotary encoder to pin 7 | |
int encoderPos = 0; // Sets initial position of encoder | |
LiquidCrystal lcd(13,12,14,15,16,17); | |
// LCD Pins Connection: | |
// NOTE: The reference for this connections is | |
// according to JP1 of the MCU Trainer. This is | |
// different when using a separate LCD display | |
// | |
// LCD RS (Pin 1) to Arduino pin 13 | |
// LCD R/W (Pin2) to GND | |
// LCD EN (Pin 3) to Arduino pin 12 | |
// LCD D4 (Pin 8) to Arduino pin 14 | |
// LCD D5 (Pin 9) to Arduino pin 15 | |
// LCD D6 (Pin 10) to Arduino pin 16 | |
// LCD D7 (Pin 11) to Arduino pin 17 | |
boolean e_ALast = LOW; | |
void setup() | |
{ | |
pinMode(e_A, INPUT); | |
pinMode(e_B, INPUT); | |
pinMode(SWITCH, INPUT); | |
digitalWrite(e_A, HIGH); | |
digitalWrite(e_B, HIGH); | |
lcd.begin(16,2); | |
lcd.print("Rotary Encoder"); // Welcome Message | |
} | |
void loop() | |
{ | |
boolean encoderA = digitalRead(e_A); | |
if ((e_ALast == HIGH) && (encoderA == LOW)) | |
{ | |
if (digitalRead(e_B) == LOW) | |
{ | |
encoderPos--; // Encoder position decreases when encoder is rotated CW | |
} | |
else | |
{ | |
encoderPos++; // Encoder position increases when encoder is rotated CCW | |
} | |
lcd.clear(); | |
lcd.setCursor(0,0); | |
lcd.print("POS:"); | |
lcd.setCursor(5,0); | |
lcd.print(encoderPos); | |
int buzzertone = encoderPos+100; | |
tone(9,buzzertone,100); | |
lcd.setCursor(0,1); | |
lcd.print("FREQ:"); | |
lcd.setCursor(6,1); | |
lcd.print(buzzertone); | |
} | |
e_ALast = encoderA; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////////////////////////// | |
// LED MONITOR // | |
// FOR eGizmo UNIVERSAL MCU TRAINER // | |
// // | |
// This serves as a sample program for // | |
// an LED monitor showing a running light // | |
// // | |
// See manual for pin assignments and sample // | |
// circuit diagram // | |
// // | |
// Codes by: // | |
// eGizmo Mechatronix Central // | |
// Taft, Manila, Philippines // | |
// http://www.egizmo.com // | |
// April 11, 2013 // | |
//////////////////////////////////////////////// | |
int DEL1 = 100; // Adjust this delay for separating functions | |
int DEL2 = 100; // Adjust this delay for individual delay of turning on/off the LEDs | |
int LED_NUMBER[] = {0,1,2,3,4,5,6,7}; | |
void setup() | |
{ | |
for(int i =0; i<=7; i++) | |
{ | |
pinMode(LED_NUMBER[i],OUTPUT); // Sets all the LED pins as OUTPUT | |
} | |
} | |
void loop() | |
{ | |
ASCENDON(); | |
delay(DEL1); | |
ASCENDOFF(); | |
delay(DEL1); | |
DESCENDON(); | |
delay(DEL1); | |
DESCENDOFF(); | |
delay(DEL1); | |
} | |
// Turns on the LEDs in ascending order | |
void ASCENDON() | |
{ | |
for(int i=0; i<=7; i++) | |
{ | |
digitalWrite(LED_NUMBER[i],HIGH); // Turns on the LEDs | |
delay(DEL2); | |
} | |
} | |
// Turns off the LEDs in ascending order | |
void ASCENDOFF() | |
{ | |
for(int i=0; i<=7; i++) | |
{ | |
digitalWrite(LED_NUMBER[i],LOW); // Turns off the LEDs | |
delay(DEL2); | |
} | |
} | |
// Turns on the LEDs in descending order | |
void DESCENDON() | |
{ | |
for(int i=7; i>=0; i--) | |
{ | |
digitalWrite(LED_NUMBER[i],HIGH); // Turns on the LEDs | |
delay(DEL2); | |
} | |
} | |
// Turns off the LEDs in descending order | |
void DESCENDOFF() | |
{ | |
for(int i=7; i>=0; i--) | |
{ | |
digitalWrite(LED_NUMBER[i],LOW); // Turns off the LEDs | |
delay(DEL2); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////////////// | |
// LCD Display #1 (MCU TRAINER) // | |
// // | |
// This sample program enables // | |
// the user to use simple // | |
// display and positioning. // | |
// // | |
// Codes by: // | |
// eGizmo Mechatronix Central // | |
// Taft, Manila, Philippines // | |
// http://www.egizmo.com // | |
//////////////////////////////////// | |
#include <LiquidCrystal.h> | |
// Includes liquid crystal library | |
LiquidCrystal lcd(13,12,14,15,16,17); | |
// LCD Pins Connection: | |
// NOTE: The reference for this connections is | |
// according to JP1 of the MCU Trainer. This is | |
// different when using a separate LCD display | |
// | |
// LCD RS (Pin 1) to Arduino pin 13 | |
// LCD R/W (Pin2) to GND | |
// LCD EN (Pin 3) to Arduino pin 12 | |
// LCD D4 (Pin 8) to Arduino pin 14 | |
// LCD D5 (Pin 9) to Arduino pin 15 | |
// LCD D6 (Pin 10) to Arduino pin 16 | |
// LCD D7 (Pin 11) to Arduino pin 17 | |
void setup() | |
{ | |
lcd.begin(16,2); | |
// Sets lcd number of rows and columns | |
} | |
// About set cursor: | |
// lcd.setCursor(row,column) | |
// NOTE: The rows and columns accepts only | |
// integers. | |
void loop() | |
{ | |
lcd.setCursor(5,0); // Sets lcd cursor | |
lcd.print("WELCOME"); // 1st line message | |
lcd.setCursor(3,1); // Sets lcd cursor to second line | |
lcd.print("to e-Gizmo"); // 2nd line message | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///////////////////////////////////// | |
// Temperature Monitor using LM34 // | |
// // | |
// This sample program allows the // | |
// MCU to read an analog reading // | |
// of a sensor specifically the // | |
// LM34 which is a temperature // | |
// sensor that reads Fahrenheit. // | |
// // | |
// Codes by: // | |
// eGizmo Mechatronix Central // | |
// Taft, Manila, Philippines // | |
// http://www.egizmo.com // | |
// April 16, 2013 // | |
///////////////////////////////////// | |
// Activates liquid crystal library: | |
#include<LiquidCrystal.h> | |
LiquidCrystal lcd(13,12,14,15,16,17); | |
// LCD Pins Connection: | |
// NOTE: The reference for this connections is | |
// according to JP1 of the MCU Trainer. This is | |
// different when using a separate LCD display | |
// | |
// LCD RS (Pin 1) to Arduino pin 13 | |
// LCD R/W (Pin2) to GND | |
// LCD EN (Pin 3) to Arduino pin 12 | |
// LCD D4 (Pin 8) to Arduino pin 14 | |
// LCD D5 (Pin 9) to Arduino pin 15 | |
// LCD D6 (Pin 10) to Arduino pin 16 | |
// LCD D7 (Pin 11) to Arduino pin 17 | |
void setup() | |
{ | |
Serial.begin(9600); // Serial communication for checking | |
lcd.begin(16,2); // Sets LCD rows and columns | |
lcd.setCursor(0,0); | |
lcd.print(" TEMPERATURE"); | |
lcd.setCursor(0,1); | |
lcd.print(" MONITOR"); | |
delay(1800); | |
lcd.clear(); | |
} | |
void loop() | |
{ | |
// Stores the sensor reading to the variable | |
int FAHRENHEIT = analogRead(A5); | |
// Formula for converting Fahrenheit to Celsius: | |
int CELSIUS = analogRead(A5)*0.5 - 32; | |
delay(1900); | |
lcd.setCursor(0,0); | |
lcd.print("Fahrenheit:"); | |
lcd.print(FAHRENHEIT); | |
lcd.setCursor(0,1); | |
lcd.print("Celsius:"); | |
lcd.print(CELSIUS); | |
// Optional serial monitor: | |
Serial.println("Fahrenheit:"); | |
Serial.println(FAHRENHEIT); | |
Serial.println("Celsius:"); | |
Serial.println(CELSIUS); | |
// NOTE: | |
// Sometimes the sensor is not calibrated therefore | |
// one must make a way to calibrate the sensor. | |
// For more information, see the data sheets of the LM34 | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///////////////////////////////////////////////////////////// | |
// Digital MCU Trainer (BUZZER 1) // | |
// // | |
// This sample program enables a programmable // | |
// tone for a buzzer with optional delay etc. // | |
// // | |
// Simply connect a wire from the headers of the buzzer // | |
// component of the trainer to any digital I/O // | |
// header located on the trainer. But for this example, // | |
// connect a wire from the buzzer to pin 9 of the // | |
// MCU extension pins. // | |
// // | |
// Codes by: // | |
// eGizmo Mechatronix Central // | |
// Taft, Manila, Philippines // | |
// http://www.egizmo.com // | |
// April 10, 2013 // | |
///////////////////////////////////////////////////////////// | |
#include "pitches.h" | |
#define BUZZER 9 | |
// Always use a PWM pin for the tone or analog write function | |
void setup() | |
{ | |
} | |
void loop() { | |
////////////////////////////////////////////////////// | |
// Note: This set of codes is just a simple // | |
// application of buzzer sounds adjusting frequency // | |
// and delay codes. // | |
// // | |
// tone(pin number, frequency) // | |
// delay(time) // | |
////////////////////////////////////////////////////// | |
tone(BUZZER,NOTE_B5); // Sets pin 7 with a frequency of 300Hz | |
delay(500); | |
tone(BUZZER,NOTE_A5); // Sets pin 7 with a frequency of 500Hz | |
delay(500); | |
tone(BUZZER,NOTE_G5); // Sets pin 7 with a frequency of 700Hz | |
delay(500); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///////////////////////////////////////////////////////////// | |
// Digital MCU Trainer (BUZZER 2) // | |
// // | |
// This sample program enables a programmable // | |
// tone for a buzzer with optional delay etc. // | |
// // | |
// Simply connect a wire from the headers of the buzzer // | |
// component of the trainer to any digital I/O // | |
// header located on the trainer. But for this example, // | |
// connect a wire from the buzzer to pin 9 of the // | |
// MCU extension pins. // | |
// // | |
// Codes by: // | |
// eGizmo Mechatronix Central // | |
// Taft, Manila, Philippines // | |
// http://www.egizmo.com // | |
// April 10, 2013 // | |
///////////////////////////////////////////////////////////// | |
#include "pitches.h" | |
#define BUZZER 9 | |
// Always use a PWM pin for the tone or analog write function | |
void setup() | |
{ | |
} | |
void loop() | |
{ | |
////////////////////////////////////////////////////// | |
// Note: This set makes use of the for loop. // | |
// It is wherein // | |
// for(initial,range,increment){ // | |
// Command here // | |
// } // | |
// tone(pin number, frequency) // | |
// delay(time) // | |
////////////////////////////////////////////////////// | |
for(int i=0;i<=560;i++) | |
{ | |
tone(BUZZER,i); | |
// Sets pin 9 with a frequency of i which is from 0 to 560. | |
// This makes a police alarm like sound. | |
delay(10); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///////////////////////////////////////// | |
// Unipolar Stepper Motor // | |
// with Rotary encoder // | |
// (eGizmo Universal MCU Trainer) // | |
// // | |
// This sample program makes use // | |
// of a unipolar stepper motor // | |
// with rotary encoder wherein // | |
// the encoder acts us a knob // | |
// for adjusting the speed of rotation // | |
// of the stepper motor. // | |
// // | |
// Codes by: // | |
// eGizmo Mechatronix Central // | |
// Taft, Manila, Philippines // | |
// http://www.egizmo.com // | |
// April 13, 2013 // | |
///////////////////////////////////////// | |
// Activates LCD Library | |
#include<LiquidCrystal.h> | |
#define e_A 5 // Connect A of rotary encoder to pin 5 | |
#define e_B 6 // Connect B of rotary encoder to pin 6 | |
#define e_switch 7 // Connect switch of rotary encoder to pin 7 | |
int e_Position = 0; | |
int e_Speed = 0; | |
boolean e_ALast = LOW; // Remembers the previous pin state | |
LiquidCrystal lcd(13,12,14,15,16,17); | |
// LCD Pins Connection: | |
// NOTE: The reference for this connections is | |
// according to JP1 of the MCU Trainer. This is | |
// different when using a separate LCD display | |
// | |
// LCD RS (Pin 1) to Arduino pin 13 | |
// LCD R/W (Pin2) to GND | |
// LCD EN (Pin 3) to Arduino pin 12 | |
// LCD D4 (Pin 8) to Arduino pin 14 | |
// LCD D5 (Pin 9) to Arduino pin 15 | |
// LCD D6 (Pin 10) to Arduino pin 16 | |
// LCD D7 (Pin 11) to Arduino pin 17 | |
void setup() | |
{ | |
Serial.begin(9600); | |
for(int pin = 8; pin<=11; pin++) | |
{ | |
pinMode(pin,OUTPUT); // Pins for stepper motor driver | |
} | |
pinMode(e_switch,OUTPUT); | |
pinMode(e_A,INPUT); | |
pinMode(e_B,INPUT); | |
digitalWrite(e_switch,HIGH); | |
digitalWrite(e_A,HIGH); | |
digitalWrite(e_B,HIGH); | |
lcd.begin(16,2); | |
} | |
void loop() | |
{ | |
int rotate = digitalRead(e_switch); // Reads rotary encoder state | |
if(rotate==0) // Is rotary encoder button pressed? | |
{ | |
lcd.setCursor(0,0); | |
lcd.print("clockwise "); | |
lcd.setCursor(7,1); | |
lcd.print("<--speed"); | |
lcd.setCursor(0,1); | |
lcd.print(e_Speed); | |
lcd.print(" "); | |
CW(); // Rotates clockwise | |
} | |
else // If not, | |
{ | |
lcd.setCursor(0,0); | |
lcd.print("ctr."); | |
lcd.setCursor(4,0); | |
lcd.print("clockwise"); | |
lcd.setCursor(7,1); | |
lcd.print("<--speed"); | |
lcd.setCursor(0,1); | |
lcd.print(e_Speed); | |
lcd.print(" "); | |
CCW(); // Rotates counter clockwise | |
} | |
} | |
void CCW() | |
{ | |
boolean encoderA = digitalRead(e_A); | |
if ((e_ALast == HIGH) && (encoderA == LOW)) | |
{ | |
if (digitalRead(e_B) == LOW) | |
{ | |
e_Position--; | |
} | |
else | |
{ | |
e_Position++; | |
} | |
} | |
e_ALast = encoderA; | |
e_Speed = 30-e_Position; | |
if(e_Speed==0) | |
{ | |
e_Position = 0; | |
} | |
// The following codes vary for certain stepper motors | |
// depending on their data pins. | |
digitalWrite(8,HIGH); | |
digitalWrite(9,LOW); | |
digitalWrite(10,LOW); | |
digitalWrite(11,LOW); | |
delay(e_Position); | |
digitalWrite(8,LOW); | |
digitalWrite(9,LOW); | |
digitalWrite(10,LOW); | |
digitalWrite(11,HIGH); | |
delay(e_Position); | |
digitalWrite(8,LOW); | |
digitalWrite(9,HIGH); | |
digitalWrite(10,LOW); | |
digitalWrite(11,LOW); | |
delay(e_Position); | |
digitalWrite(8,LOW); | |
digitalWrite(9,LOW); | |
digitalWrite(10,HIGH); | |
digitalWrite(11,LOW); | |
delay(e_Position); | |
} | |
void CW() | |
{ | |
boolean encoderA = digitalRead(e_A); | |
if ((e_ALast == HIGH) && (encoderA == LOW)) | |
{ | |
if (digitalRead(e_B) == LOW) | |
{ | |
e_Position++; | |
} | |
else | |
{ | |
e_Position--; | |
} | |
} | |
e_ALast = encoderA; | |
e_Speed = 30-e_Position; | |
if(e_Speed==0) | |
{ | |
e_Position = 0; | |
} | |
// The following codes vary for certain stepper motors | |
// depending on their data pins. | |
digitalWrite(8,LOW); | |
digitalWrite(9,LOW); | |
digitalWrite(10,HIGH); | |
digitalWrite(11,LOW); | |
delay(e_Position); | |
digitalWrite(8,LOW); | |
digitalWrite(9,HIGH); | |
digitalWrite(10,LOW); | |
digitalWrite(11,LOW); | |
delay(e_Position); | |
digitalWrite(8,LOW); | |
digitalWrite(9,LOW); | |
digitalWrite(10,LOW); | |
digitalWrite(11,HIGH); | |
delay(e_Position); | |
digitalWrite(8,HIGH); | |
digitalWrite(9,LOW); | |
digitalWrite(10,LOW); | |
digitalWrite(11,LOW); | |
delay(e_Position); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment