0
Please help me on programming for my project..there I use arduino mega board,sg90 and coin hopper...
in that I give total amount,then cost for the product is given.by using that,codes has to subtract total amount with product cost and provides remaining amount..I programmed one bt it doesn't work for the above process. #include<Servo.h> Servo servomain; int led=13; long int x=0; void setup() { Serial.begin(9600); pimMode(led,OUTPUT); servomain.attach(5);} void loop() { servomain.write(120);delay(10); while(Serial.available()>0) { int x=Serial.parseInt(); while(x>0) { servomain.write(40);delay(170);
1 ответ
0
Need more information. The code you put in looks like it moves a servo, but it's a little disconnected. The servo moves, and if it receives data from the serial port it moves to point 40 on the servo for 170 milliseconds, then it moves back to the 120 position.
So you have a hopper of coins, and you are letting one out with each serial burst of integers.
There is a small bug in your code - pimMode(led,OUTPUT) should be pinMode(led,OUTPUT).
I would look at maybe sending data that is useful to the arduino, like looking a particular coin slot ("openslot1") as a command.
Also I would put some kind of feedback to make sure the coin(s) dropped.