fork download
  1. #include <Servo.h>
  2.  
  3. Servo servo;//サーボのインスタンス
  4. byte val=90;
  5. static int angle=0;
  6.  
  7. void setup() {
  8. Serial.begin(9600);
  9. servo.attach(3);
  10. }
  11.  
  12. void loop(){
  13. if(Serial.available() > 0){
  14. val = Serial.read();
  15. if('0' <= val && val <= '9') // 0~9の文字
  16. {
  17. // 180を超えない範囲で元の値を10倍して1の位へ加算
  18. if(((angle*10)+val-'0')<180) angle=(angle*10)+val-'0';
  19. else Serial.print('\a'); // Error BEEP to terminal
  20. }
  21. else if(val == '\r') // ENTERキーでサーボ更新
  22. {
  23. servo.write(angle);
  24. }
  25. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:19: error: Servo.h: No such file or directory
prog.cpp:3: error: ‘Servo’ does not name a type
prog.cpp:4: error: ‘byte’ does not name a type
prog.cpp: In function ‘void setup()’:
prog.cpp:8: error: ‘Serial’ was not declared in this scope
prog.cpp:9: error: ‘servo’ was not declared in this scope
prog.cpp: In function ‘void loop()’:
prog.cpp:13: error: ‘Serial’ was not declared in this scope
prog.cpp:14: error: ‘val’ was not declared in this scope
prog.cpp:23: error: ‘servo’ was not declared in this scope
prog.cpp:25: error: expected `}' at end of input
stdout
Standard output is empty