Advertisement
Guest User

Untitled

a guest
Jul 11th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. int LedPin = 13;
  2. char data;
  3.  
  4. void setup()
  5. {
  6. Serial.begin(9600);
  7. pinMode( LedPin , OUTPUT );
  8. }
  9.  
  10. void loop()
  11. {
  12. data = Serial.read();
  13. if (Serial.available() > 0)
  14. {
  15. if(data == '1' )
  16. {
  17. digitalWrite(LedPin,HIGH);
  18. }
  19. else if(data == '0' )
  20. {
  21. digitalWrite(LedPin,LOW);
  22. }
  23. }
  24. else
  25. if (Serial.available()<0)
  26. {
  27. digitalWrite(LedPin,HIGH);
  28. delay(500);
  29. digitalWrite(LedPin,LOW);
  30. delay(500);
  31. }
  32. }
  33.  
  34. public class Blink extends JArduino {
  35.  
  36. public Blink(String port) {
  37. super(port);
  38. }
  39.  
  40. @Override
  41. protected void setup() {
  42. // initialize the digital pin as an output.
  43. // Pin 13 has an LED connected on most Arduino boards:
  44. pinMode(DigitalPin.PIN_12, PinMode.OUTPUT);
  45. }
  46.  
  47. @Override
  48. protected void loop() {
  49. // set the LED on
  50. digitalWrite(DigitalPin.PIN_12, DigitalState.HIGH);
  51. delay(1000); // wait for a second
  52. // set the LED off
  53. digitalWrite(DigitalPin.PIN_12, DigitalState.LOW);
  54. delay(1000); // wait for a second
  55. }
  56.  
  57. public static void main(String[] args) {
  58. String serialPort;
  59. if (args.length == 1) {
  60. serialPort = args[0];
  61. } else {
  62. serialPort = Serial4JArduino.selectSerialPort();
  63. }
  64. JArduino arduino = new Blink(serialPort);
  65. arduino.runArduinoProcess();
  66. }
  67.  
  68. CommPort arduino = getArduinoPort();
  69. arduino.getOutputStream().write(1);
  70.  
  71. public CommPort getArduinoPort() {
  72. Enumeration ports = CommPortIdentifier.getPortIdentifiers();
  73. while(ports.hasMoreElements()) {
  74. CommPortIdentifier identifier = (CommPortIdentifier) ports.nextElement();
  75. if(isArduino(identifier)) {
  76. return identifier.open(getClass().getName(), 2000); // 2 second timeout
  77. }
  78. }
  79. return null;
  80. }
  81.  
  82. public boolean isArduino(CommPortIdentifier identifier) {
  83. // if you know the name of the port ahead of time you can
  84. // compare it here with identifier.getName(), otherwise
  85. // you can interface with the user like the Arduino IDE's
  86. // serial monitor
  87. }
  88.  
  89. import static processing.hardware.arduino.cores.arduino.Arduino.*;
  90.  
  91. public class Blink {
  92. static byte ledPin = 13; // LED connected to digital pin 13
  93.  
  94. public static void setup() {
  95. pinMode(ledPin, OUTPUT); // sets the digital pin as output
  96. }
  97.  
  98. public static void loop() // run over and over again
  99. {
  100. digitalWrite(ledPin, HIGH); // sets the LED on
  101. delay(500); // waits for a second
  102. digitalWrite(ledPin, LOW); // sets the LED off
  103. delay(500); // waits for a second
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement