Bladeren bron

Add brickup library to control the robot.

Wesley Tsai 8 jaren geleden
commit
a46ca62fb8
2 gewijzigde bestanden met toevoegingen van 134 en 0 verwijderingen
  1. 80 0
      I2CRobot.cpp
  2. 54 0
      I2CRobot.h

+ 80 - 0
I2CRobot.cpp

@@ -0,0 +1,80 @@
1
+/*
2
+Copyright (C) 2016 Wesley Tsai (wesleyboy42@gmail.com)
3
+
4
+Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+this software and associated documentation files (the "Software"), to deal in
6
+the Software without restriction, including without limitation the rights to
7
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+the Software, and to permit persons to whom the Software is furnished to do so,
9
+subject to the following conditions:
10
+
11
+The above copyright notice and this permission notice shall be included in all
12
+copies or substantial portions of the Software.
13
+
14
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+*/
21
+
22
+/*
23
+ * Library for controlling robot via I2C.
24
+ *
25
+ * Information about the makercup obtained from:
26
+ * https://medium.com/maker-cup
27
+ */
28
+
29
+
30
+// --------------------------------------------------------------------------------------
31
+
32
+#include "I2CRobot.h"
33
+#include <Wire.h>
34
+
35
+// --------------------------------------------------------------------------------------
36
+
37
+I2CRobot::I2CRobot(byte ID):_ID(ID)
38
+{
39
+
40
+}
41
+
42
+I2CRobot::~I2CRobot()
43
+{
44
+
45
+}
46
+
47
+// --------------------------------------------------------------------------------------
48
+
49
+void I2CRobot::init()
50
+{
51
+    Wire.begin();
52
+}
53
+
54
+void I2CRobot::hello(void)
55
+{
56
+  Wire.beginTransmission(_ID);
57
+  Wire.write(_hello);
58
+  Wire.endTransmission();
59
+}
60
+
61
+void I2CRobot::order(void)
62
+{
63
+  Wire.beginTransmission(_ID);
64
+  Wire.write(_order);
65
+  Wire.endTransmission();
66
+}
67
+
68
+void I2CRobot::check(void)
69
+{
70
+  Wire.beginTransmission(_ID);
71
+  Wire.write(_check);
72
+  Wire.endTransmission();
73
+}
74
+
75
+void I2CRobot::custom(byte custom)
76
+{
77
+  Wire.beginTransmission(_ID);
78
+  Wire.write(custom);
79
+  Wire.endTransmission();
80
+}

+ 54 - 0
I2CRobot.h

@@ -0,0 +1,54 @@
1
+/*
2
+Copyright (C) 2016 Wesley Tsai (wesleyboy42@gmail.com)
3
+
4
+Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+this software and associated documentation files (the "Software"), to deal in
6
+the Software without restriction, including without limitation the rights to
7
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+the Software, and to permit persons to whom the Software is furnished to do so,
9
+subject to the following conditions:
10
+
11
+The above copyright notice and this permission notice shall be included in all
12
+copies or substantial portions of the Software.
13
+
14
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+*/
21
+
22
+/*
23
+ * Library for controlling robot via I2C.
24
+ *
25
+ * Information about the makercup obtained from:
26
+ * https://medium.com/maker-cup
27
+ */
28
+
29
+#ifndef __I2CRobot_h__
30
+#define __I2CRobot_h__
31
+
32
+#include "Arduino.h"
33
+
34
+class I2CRobot
35
+{
36
+public:
37
+    I2CRobot(byte ID);
38
+    ~I2CRobot();
39
+
40
+    void init(void);
41
+    void hello(void);
42
+    void order(void);
43
+    void check(void);
44
+    void custom(byte custom);
45
+
46
+private:
47
+    byte _ID=8;
48
+    byte _hello=254;
49
+    byte _order=253;
50
+    byte _check=252;
51
+
52
+};
53
+
54
+#endif