Question

In the code below i am using a LS-3006 SERVO on the arduino uno and everytime...

In the code below i am using a LS-3006 SERVO on the arduino uno and everytime i hit the pushbutton to input a time the servo comes on. Would anyone be able to tell me what a solution is to this problem? Thanks

#include <Wire.h>
#include <DS3231.h>
#include <Servo.h>
#include <LiquidCrystal.h>
#include <Keypad.h>

const byte ROWS = 4; // # of rows
const byte COLS = 4; // # of columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 2, 3, 4, 5 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 6, 7, 8, 9 };
// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

DS3231 rtc(A4, A5);
Servo servo_test;      //initialize a servo object for the connected servo
LiquidCrystal lcd(A0, A1, A2, 11, 12, 13); // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7)

//int angle = 0;   
// int potentio = A0;      // initialize the A0analog pin for potentiometer
int t1, t2, t3, t4, t5, t6;

boolean feed = true; // condition for alarm
char key;
int r[6];


void setup()
{
servo_test.attach(9);   // attach the signal pin of servo to pin9 of arduino
rtc.begin();
lcd.begin(16,2);
servo_test.write(1500);
Serial.begin(9600);
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);

// pinMode(9,OUTPUT);


}

void loop()
{
lcd.setCursor(0,0);
int buttonPress;
buttonPress = digitalRead(A3);
if (buttonPress==1)
setFeedingTime();

//Serial.println(buttonPress);
lcd.print("Time: ");
String t = "";
t = rtc.getTimeStr();
t1 = t.charAt(0)-48;
t2 = t.charAt(1)-48;
t3 = t.charAt(3)-48;
t4 = t.charAt(4)-48;
t5 = t.charAt(6)-48;
t6 = t.charAt(7)-48;

lcd.print(rtc.getTimeStr());
lcd.setCursor(0,1);
lcd.print("Date: ");
lcd.print(rtc.getDateStr());
//////
    if (t1==r[0] && t2==r[1] && t3==r[2] && t4==r[3]&& t5<1 && t6<3 && feed==true)
{

servo_test.write(100);   //command to rotate the servo to the specified angle
delay(400);  
servo_test.write(180);
delay(2000);
servo_test.write(90);
delay(2000);
feed=false;


}
}      
void setFeedingTime()
{
feed = true;
   int i=0;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Set feeding Time");
lcd.clear();
lcd.print("HH:MM");
lcd.setCursor(0,1);

while(1){
    key = kpd.getKey();
    char j;
   
if(key!=NO_KEY){
   
    lcd.setCursor(j,1);
   
    lcd.print(key);
   
    r[i] = key-48;
    i++;
    j++;
    if (j==2)
    {
      lcd.print(":"); j++;
    }
    delay(500);
}
if (key == '#')
{key=0; break; }
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

you can try two options:

1)putting a delay after the getkey() function in setFeedingTime() method.

2)making feed = true only when all the feed time input is received that is inside the if (key == '#) condition block.

because the servo rotate function block will only be called once feed is true

Add a comment
Know the answer?
Add Answer to:
In the code below i am using a LS-3006 SERVO on the arduino uno and everytime...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 14. 10 pts. You have the following code lines in an Arduino c++ sketch to blink an LED and control a standard servo (not a continuous servo) and buzzer: #include <Servo.h> Servo frontSer...

    14. 10 pts. You have the following code lines in an Arduino c++ sketch to blink an LED and control a standard servo (not a continuous servo) and buzzer: #include <Servo.h> Servo frontServo; int time 2500; int multiple 3; int leg-5 int red 2; void setup()X pinMode(red,OUTPUT) frontServo.attach(leg): pinMode(4, OUTPUT) void looplf frontServo.write(0); digitalWrite(red, HIGH); delay(time); tone(4,400,500); digitalWrite(red,LOW); time-time"multiple; delay(time); Answer the following: What pin should the LED be connected to? what pin should the information lead wire of the...

  • I am trying to program my Arduino UNO to implement a flashing pattern with two LEDs....

    I am trying to program my Arduino UNO to implement a flashing pattern with two LEDs. When one LED is off, the other must be on. The program needs to be done in assembly. I have a working program in c++ but I need to convert it to assembly. Here is my c++ program: int led = 13; int led2 = 12; void setup() {    pinMode(led, OUTPUT); pinMode(led2, OUTPUT); } void loop() { digitalWrite(led, HIGH);    delay(1000); digitalWrite(led, LOW);...

  • Please explain to me how the following arduino code control the smart home system design below. #...

    Please explain to me how the following arduino code control the smart home system design below. #include "ESP8266.h" #include <Wire.h> #include <LiquidCrystal_I2C.h> #include <dht.h> #define DATA_PIN 2 #define SSID       "abc" #define PASSWORD   "12345678" byte termometerLogo[8] = {     B00100,     B01010,     B01010,     B01110,     B01110,     B11111,     B11111,     B01110 }; byte humidityLogo[8] = {     B00100,     B00100,     B01010,     B01010,     B10001,     B10001,     B10001,     B01110, }; SoftwareSerial mySerial(10,11); ESP8266 wifi(mySerial); LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); dht DHT; char buffData[150]; const int...

  • I am doing an Arduino Uno project where I made a "Simon says" memory game with 3 neopixel LED str...

    I am doing an Arduino Uno project where I made a "Simon says" memory game with 3 neopixel LED strips and 3 - ultrasonics. I have them working independently but I need to combine the code so they work together. Here is what I have: Memory Game #define PLAYER_WAIT_TIME 2000 // The time allowed between button presses - 2s byte sequence[100]; // Storage for the light sequence byte curLen = 0; // Current length of the sequence byte inputCount =...

  • Assignment 4 File “quad_sol.s” contains a quadratic polynomial solver, which calculates the integer solution of a quadratic polynomial equation. 1. Rewrite the program using instructions reordering to...

    Assignment 4 File “quad_sol.s” contains a quadratic polynomial solver, which calculates the integer solution of a quadratic polynomial equation. 1. Rewrite the program using instructions reordering to reduce the number of cycles needed to execute the program. Indicate the number of cycle reduction. 2. Describe how forwarding would affect the execution of the program. CODE # quad_sol.s # This assembly program calculates the integer solutions of a quadratic polynomial. # Inputs : The coefficients a,b,c of the equation a*x^2 +...

  • C++ how can I fix these errors this is my code main.cpp #include "SpecialArray.h" #include <...

    C++ how can I fix these errors this is my code main.cpp #include "SpecialArray.h" #include <iostream> #include <fstream> #include <string> using namespace std; int measureElementsPerLine(ifstream& inFile) {    // Add your code here.    string line;    getline(inFile, line);    int sp = 0;    for (int i = 0; i < line.size(); i++)    {        if (line[i] == ' ')            sp++;    }    sp++;    return sp; } int measureLines(ifstream& inFile) {    // Add your code here.    string line;    int n = 0;    while (!inFile.eof())    {        getline(inFile,...

  • C++ Linux Question : Remove Nth Node from end of list Given a linked list, remove...

    C++ Linux Question : Remove Nth Node from end of list Given a linked list, remove the n-th node from the end of list and return its head. Example: Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked list becomes 1->2->3->5. Note: Given n will always be valid. (i.e. n is greater than 0) Follow up: Could you do this in one pass? Hint: Maintain two pointers and update one with...

  • I just need a help in replacing player 2 and to make it unbeatable here is my code: #include<i...

    I just need a help in replacing player 2 and to make it unbeatable here is my code: #include<iostream> using namespace std; const int ROWS=3; const int COLS=3; void fillBoard(char [][3]); void showBoard(char [][3]); void getChoice(char [][3],bool); bool gameOver(char [][3]); int main() { char board[ROWS][COLS]; bool playerToggle=false; fillBoard(board); showBoard(board); while(!gameOver(board)) { getChoice(board,playerToggle); showBoard(board); playerToggle=!playerToggle; } return 1; } void fillBoard(char board[][3]) { for(int i=0;i<ROWS;i++) for(int j=0;j<COLS;j++) board[i][j]='*'; } void showBoard(char board[][3]) { cout<<" 1 2 3"<<endl; for(int i=0;i<ROWS;i++) { cout<<(i+1)<<"...

  • Need C++ coding for this lab exercise given below :) 4. Lab Exercise — Templates Exercise...

    Need C++ coding for this lab exercise given below :) 4. Lab Exercise — Templates Exercise 1 - Function Templating For this part of the lab make a template out of the myMax function and test it on different data types. Copy maxTemplate.cpp to your Hercules account space. Do that by: Entering the command:cp /net/data/ftp/pub/class/115/ftp/cpp/Templates/maxTemplate.cpp maxTemplate.cpp Compile and run the program to see how it works. Make a template out of myMax. Don't forget the return type. Modify the prototype appropriately. Test your myMax template on int, double,...

  • 5. Consider the SPIM code below. globl main .text main: ori $t1, $0, 10 ori $t2,...

    5. Consider the SPIM code below. globl main .text main: ori $t1, $0, 10 ori $t2, $0, 11 add $t3, $t1,$t2 move $t4, $t3 The following image shows a screen shot of QtSPIM page when this program is loaded, and executed in step-by step fashion. Current instruction is highlighted. Data Text x Text Regs Int Regs [16] Int Regs [16] PC = 400028 EPC 0 Cause = 0 BadAddr = 0 Status = 3000ff10 HI LO = 0 = 0...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT