kail123
Newbie level 4
- Joined
- Jan 23, 2013
- Messages
- 5
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,331
Hi Guys , I have below code from Arduino and need help to change it to MikroC . the reason of this just to see how is MikroC will be changed the Function code .. i am going to use 16f877 with Osc 10 Mhz , using any port setup no issue for me , i will modify it later on . The code is controlling the speed of DC Motor with one Button .
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 int switchPin = 8; int MotorPin = 11; boolean lastButton = LOW; boolean currentButton = LOW; int MotorSpeed = 0; void setup() { pinMode(switchPin, INPUT); pinMode(MotorPin, OUTPUT); } boolean debounce(boolean last) { boolean current = digitalRead(switchPin); if (last != current) { delay(5); current = digitalRead(switchPin); } return current; } void loop() { currentButton = debounce(lastButton); if (lastButton == LOW && currentButton == HIGH) { MotorSpeed = MotorSpeed + 61; } lastButton = currentButton; if (MotorSpeed > 255) MotorSpeed = 0; analogWrite(MotorPin, MotorSpeed); }
Last edited by a moderator: