Advertisement
Guest User

Electric Imp PWM Lego Train Control

a guest
Jul 9th, 2013
127
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None
  1.  
  2. class Servo extends InputPort
  3. {
  4. type = "float";
  5. pin = null;
  6.  
  7. // define a constructor so that we can construct seperate instances for servos 1 and 2
  8. constructor(name, pin) {
  9. // call through to the base (InputPort) constructor with the provided name
  10. base.constructor(name)
  11. this.pin = pin
  12. // no need to configure the pins as we've already done it at global scope
  13. }
  14.  
  15. function set(value)
  16. {
  17. // Display on our Planner node
  18. server.show(pin + "=" + value);
  19.  
  20. pin.configure(PWM_OUT, 0.000870, value);
  21. }
  22. }
  23.  
  24. imp.configure("PWM Test", [Servo("Channel1", hardware.pin1), Servo("Channel2", hardware.pin2)], []);
  25.  
  26. // Display our message
  27. server.connect();
  28. server.show("PWM Test Started!");
  29. server.log("PWM Test Started");
  30.  
  31. // Setup I/O
  32. hardware.pin1.configure(PWM_OUT, 0.000870, 0.0);
  33.  
  34. hardware.pin2.configure(DIGITAL_OUT);
  35. hardware.pin2.write(0);
Advertisement
RAW Paste Data Copied
Advertisement