Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed Stepper_Motor_X27168
main.cpp
- Committer:
- aalbul3
- Date:
- 2019-05-01
- Revision:
- 2:12b24ae1dc9f
- Parent:
- 1:b15bda5fafa8
File content as of revision 2:12b24ae1dc9f:
#include "mbed.h"
#include "StepperMotor_X27168.h"
#include "Dht11.h"
/*
StepperMotor_X27168 smotor(p26, p25, p34, p36);
StepperMotor_X27168 smotor2(p5,p6,p14,p25);
DigitalOut motor1(p30);
DigitalOut motor2(p8);
int main() {
motor1=0;
motor2=1;
// smotor.set_speed(1200);
smotor.set_max_position(180);
int i=0;
while (1){
while (i<180) {
smotor2.step(0);
wait(.1);
i++;
}
while (i>0) {
smotor2.step(1);
wait(.1);
i--;
}
}
}
*/
/*
Serial pc(USBTX, USBRX);
Dht11 sensor(p21);
int main() {
while (1) {
sensor.read();
pc.printf("T: %f, H: %d\r\n", sensor.getFahrenheit(), sensor.getHumidity());
wait(1);
}
}
*/
/*
Serial pc (USBTX,USBRX);
StepperMotor_X27168 smotor2(p5,p6,p14,p25);
DigitalOut motor2(p8);
StepperMotor_X27168 smotor(p26, p25, p34, p36);
DigitalOut motor1(p30);
Dht11 sensor(p21);
Serial device(p9,p10); //9-10 11u; 28-27 1768
volatile int c; // Initialized to the NULL character
DigitalOut led(LED1);
DigitalOut mbedp(p22);
volatile int check = 0;
volatile int check1 = 0;
Ticker waker;
volatile int ste=0;
volatile float temp;
volatile int ye= 1;
volatile int ste1;
volatile int ste2;
void onCharReceived() {
c = device.getc();
check = 1;
}
void flip() {
mbedp = 0;
}
Ticker flipper;
Ticker mbede;
void flip1() {
check1 = 1;
}
void flip2() {
ye = 1;
}
int main() {
device.baud(9600);
flipper.attach(&flip1, 150); //Ticker to wake up the 11u24 for normal updating of time and temperature right now set at 2.5 minutes
mbede.attach(&flip2, 600); //Ticker to wake up the 1768 as well. Set currently for 10 minutes.
smotor2.set_max_position(360);
// motor2=1; ////////////////////////
//flipper.attach(&flip1, 1.5);
/*
while(1) {
sleep();
}
ste = ste+40;
smotor2.step_position(ste);
wait(.5);
check1 = 0;
}
*/
/*
device.attach(&onCharReceived);
while (1) {
if (ye == 1) {
mbedp = 1;
wait(3); //Let it power up properly
while (check == 0) {wait(.2);}
pc.putc(device.getc());
led = 1;
device.putc(ste+20); //This will be the step # it is on atm.
while (check == 0) {wait(.5); }
check = 0;
//First character will be time
//store it
device.putc(1); //Confirmation that time is received
while (check == 0) {wait(.5); } //wait for 1768 to move motor
check = 0; //done. 1768 ready to be powered down.
mbedp = 0; ///mbed 1768 powered down.
ye = 0;
}
sensor.read();
wait(2); //let the DHT 11 respond clearly
sensor.read();
temp = sensor.getFahrenheit(); //Now we have Fahrenheit
ste2 = (temp-60)*25/360; //This is the step it should be on
motor2 = 1;
if (ste1 <= 360 && ste1 > 0) {smotor2.step_position(ste2); wait(1.0);} //let it wait to settle
motor2 = 0;
//This will be new position of motor 2(temp)
//Now onto to the motors.
//Need to figure out time!
//Here will be the temp. Scale it from 60 to 85 across 360
while (check1 == 0) {sleep();} //Sleep until the next ticker
}
/*
while (true)
{
if (c == 180)
{
c = 0; // To avoid execution of this block until a '1' is received again.
//mbedp = 0;
waker.attach(&flip, 50);
sleep();
mbedp=0;
}
if (c == 0)
{
// c = '\0'; // To avoid execution of this block until a '0' is received again.
led = 0;
}
}
*/
//}
Dht11 sensor(p21);
DigitalIn commun(p23);
DigitalOut mbedp(p22);
volatile int check = 0;
DigitalOut led2(LED2);
DigitalOut led(LED1);
volatile int check1 = 0;
volatile int ye = 1;
Ticker waker;
Ticker waker2;
void flip1() {
check1 = 1;
}
void flip2() {
ye = 1;
}
StepperMotor_X27168 smotor(p26, p25, p34, p36);
StepperMotor_X27168 smotor2(p5,p6,p14,p25);
DigitalOut motor1(p30);
DigitalOut motor2(p8);
Serial device(p9,p10);
Serial pc(USBTX,USBRX);
volatile int c = 0;
void onCharReceived() {
c = device.getc();
led = ~led;
check = 1;
}
int main() {
waker.attach(&flip1, 150); //Ticker to wake up the 11u24 for normal updating of time and temperature right now set at 2.5 minutes
waker2.attach(&flip2, 600);
if (ye == 1) {
mbedp = 1;
wait(10);
mbedp = 0;
ye = 0;
}
float temp; float humid;
sensor.read();
temp = sensor.getFahrenheit(); //Now we have Fahrenheit
humid = sensor.getHumidity();
//pc.printf("T: %f, H: %d\r\n", sensor.getFahrenheit(), sensor.getHumidity());
temp = temp-60;
temp = temp*360/25;
int ste = (int)temp;
motor2 = 1;
smotor2.step_position(ste);
wait(.5);
motor2 = 0;
humid = humid *360/100;
motor1 = 1;
smotor.step_position(humid);
wait(.5);
motor1 = 0;
while (check1 == 0) {deepsleep();}
check1 = 0;
}