diff --git a/src/tec/letsgoing/ardublock/simulator/Simulator.java b/src/tec/letsgoing/ardublock/simulator/Simulator.java index 01a06231bde0d4625777c8afc1f05f8f1a38ed9a..ca867aa62dfa7f69c419b69be64dd581f67d3d37 100644 --- a/src/tec/letsgoing/ardublock/simulator/Simulator.java +++ b/src/tec/letsgoing/ardublock/simulator/Simulator.java @@ -19,6 +19,8 @@ import tec.letsgoing.ardublock.simulator.simcode.datatypes.SimTypeInt; import tec.letsgoing.ardublock.simulator.simcode.datatypes.SimTypeString; import tec.letsgoing.ardublock.simulator.simcode.functions.CodeExecuteFunction; import tec.letsgoing.ardublock.simulator.simcode.functions.SimCodeFunction; +import tec.letsgoing.ardublock.simulator.simcode.io.CodeAnalogRead; +import tec.letsgoing.ardublock.simulator.simcode.io.CodeAnalogWrite; import tec.letsgoing.ardublock.simulator.simcode.io.CodeDigitalWrite; import tec.letsgoing.ardublock.simulator.simcode.math.CodeAdd; import tec.letsgoing.ardublock.simulator.simcode.vars.CodeMillis; @@ -26,6 +28,11 @@ import tec.letsgoing.ardublock.simulator.view.GUI; /** * @author Lucas + * + * Pinmapping: + * RGB: 9,10,11 + * Poti: A5 + * Button: 3,4,5 */ public class Simulator implements Runnable, ActionListener { @@ -179,32 +186,35 @@ public class Simulator implements Runnable, ActionListener { public static void main(String[] args) throws InterruptedException { Vector<SimCode> testSetup = new Vector<SimCode>(); Vector<SimCode> testLoop = new Vector<SimCode>(); - int testdelay = 500; + int testdelay = 200; SimTypeBool b1 = new SimTypeBool(true); SimTypeBool b0 = new SimTypeBool(false); SimTypeString s1 = new SimTypeString("CodeString Test"); - SimTypeInt d1 = new SimTypeInt(5); - SimTypeInt d5 = new SimTypeInt(23); - SimTypeInt d2 = new SimTypeInt(0); - SimTypeInt d3 = new SimTypeInt(1); + SimTypeInt d1 = new SimTypeInt(9); + SimTypeInt d5 = new SimTypeInt(5); + SimTypeInt d3 = new SimTypeInt(0); + SimTypeInt d9 = new SimTypeInt(9); SimTypeInt delay = new SimTypeInt(testdelay); SimTypeString s2 = new SimTypeString(d1); CodeAdd s5 = new CodeAdd(d1, d5); - testLoop.add(new CodeDigitalWrite(d2, b0)); - testLoop.add(new CodeDelay(delay)); - testLoop.add(new CodeDigitalWrite(d2, b1)); - testLoop.add(new CodeDelay(delay)); + //testLoop.add(new CodeDigitalWrite(d2, b0)); + //testLoop.add(new CodeDelay(delay)); + //testLoop.add(new CodeDigitalWrite(d2, b1)); + //testLoop.add(new CodeDelay(delay)); Vector<SimCode> forVec = new Vector<SimCode>(); forVec.add(new CodeDigitalWrite(d3, b1)); forVec.add(new CodeDelay(delay)); forVec.add(new CodeDigitalWrite(d3, b0)); forVec.add(new CodeDelay(delay)); - testLoop.add(new CodeFor(d1, forVec)); - testLoop.add(new CodeSerialPrint(new SimTypeString(new CodeMillis()), b1)); + //testLoop.add(new CodeFor(d1, forVec)); + //testLoop.add(new CodeSerialPrint(new SimTypeString(new CodeMillis()), b1)); + testLoop.add(new CodeSerialPrint(new SimTypeString(new CodeAnalogRead(d5)),b1)); + testLoop.add(new CodeAnalogWrite(d9,new SimTypeInt(new CodeAnalogRead(d5)))); + testLoop.add(new CodeDelay(delay)); SimCodeFunction setupCode = new SimCodeFunction("setup", testSetup); SimCodeFunction loopCode = new SimCodeFunction("loop", testLoop); diff --git a/src/tec/letsgoing/ardublock/simulator/view/GUI.java b/src/tec/letsgoing/ardublock/simulator/view/GUI.java index 025ca54e5e3cedcf57e382962ecf4c5c01491a28..4b560d312d6c7513464919f216fdb64e91936a4c 100644 --- a/src/tec/letsgoing/ardublock/simulator/view/GUI.java +++ b/src/tec/letsgoing/ardublock/simulator/view/GUI.java @@ -65,6 +65,7 @@ public class GUI extends JFrame implements Runnable, ActionListener { mainPane.add(createControlPanel(simu), BorderLayout.LINE_END); mainPane.add(createSerialLog(), BorderLayout.PAGE_END); this.pack(); + //this.setLocation(-1000, 0); Code to Run the Window on seconds screen this.setVisible(true); } diff --git a/src/tec/letsgoing/ardublock/simulator/view/modules/Button.java b/src/tec/letsgoing/ardublock/simulator/view/modules/Button.java index 092a23ecdfb071b0ee132c92809c8be568ecacb7..cd633187d659acd7817e6e42aa5780d0aba19508 100644 --- a/src/tec/letsgoing/ardublock/simulator/view/modules/Button.java +++ b/src/tec/letsgoing/ardublock/simulator/view/modules/Button.java @@ -79,15 +79,15 @@ public class Button extends Modul implements ActionListener { } public boolean connect(Arduino arduino) { - Pin tmpPin = arduino.getPin(11); + Pin tmpPin = arduino.getPin(3); this.addPin(tmpPin); tmpPin.setObserver(this); - tmpPin = arduino.getPin(12); + tmpPin = arduino.getPin(4); this.addPin(tmpPin); tmpPin.setObserver(this); - tmpPin = arduino.getPin(13); + tmpPin = arduino.getPin(5); this.addPin(tmpPin); tmpPin.setObserver(this); diff --git a/src/tec/letsgoing/ardublock/simulator/view/modules/Poti.java b/src/tec/letsgoing/ardublock/simulator/view/modules/Poti.java index 2ab4e96b0862899383b0ddd10c2b3bde6edd42ad..be3ad1e1594f6f40685880c749711d186753d6aa 100644 --- a/src/tec/letsgoing/ardublock/simulator/view/modules/Poti.java +++ b/src/tec/letsgoing/ardublock/simulator/view/modules/Poti.java @@ -6,6 +6,10 @@ package tec.letsgoing.ardublock.simulator.view.modules; import java.awt.Dimension; import javax.swing.ImageIcon; import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JSlider; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; import tec.letsgoing.ardublock.simulator.arduino.Arduino; import tec.letsgoing.ardublock.simulator.arduino.Pin; @@ -14,8 +18,9 @@ import tec.letsgoing.ardublock.simulator.arduino.Pin; * @author Lucas * */ -public class Poti extends Modul { +public class Poti extends Modul implements ChangeListener { int value = 0; + JSlider slider; public Poti(ImageIcon _icon) { layerpane.setPreferredSize(new Dimension(294, 294)); @@ -23,16 +28,43 @@ public class Poti extends Modul { ImageIcon chipIcon = _icon; chiplabel.setIcon(chipIcon); chiplabel.setSize(294, 294); - layerpane.add(chiplabel, 1); - + slider=new JSlider(JSlider.HORIZONTAL,0,1024,512); + + slider.setMajorTickSpacing(256); + slider.setMinorTickSpacing(64); + slider.setPaintTicks(true); + slider.setPaintLabels(true); + slider.setPreferredSize(new Dimension(180,50)); + slider.setOpaque(false); + slider.addChangeListener(this); + + JPanel sliderPanel=new JPanel(); + sliderPanel.add(slider); + sliderPanel.setSize(200, 50); + sliderPanel.setLocation(47,170); + sliderPanel.setOpaque(false); + layerpane.add(chiplabel, 0); + layerpane.add(sliderPanel,0); + + } public void updateModul(Pin arg0) { - + if (pins.get(0).getValue()!=slider.getValue()) { + pins.get(0).setValue(slider.getValue()); + } } public boolean connect(Arduino arduino) { - + this.addPin(arduino.getPin(5+13)); + arduino.getPin(5+13).setObserver(this); return true; } + + @Override + public void stateChanged(ChangeEvent arg0) { + if (slider.getValue()==1024) slider.setValue(1023); //Kleiner Trick damit die 1024 angezeigt wird aber keinen Fehler verursacht + pins.get(0).setValue(slider.getValue()); + + } } diff --git a/src/tec/letsgoing/ardublock/simulator/view/modules/RGB.java b/src/tec/letsgoing/ardublock/simulator/view/modules/RGB.java index 8ee84cd336eb52d59220edbd7b0580b37aae69df..104e87e87559a379f74eae67812ded31db852433 100644 --- a/src/tec/letsgoing/ardublock/simulator/view/modules/RGB.java +++ b/src/tec/letsgoing/ardublock/simulator/view/modules/RGB.java @@ -57,15 +57,15 @@ public class RGB extends Modul { public boolean connect(Arduino arduino) { // TODO Pins= R G B ? Aktuell RBG - Pin tmpPin = arduino.getPin(0); + Pin tmpPin = arduino.getPin(9); this.addPin(tmpPin); tmpPin.setObserver(this); - tmpPin = arduino.getPin(1); + tmpPin = arduino.getPin(10); this.addPin(tmpPin); tmpPin.setObserver(this); - tmpPin = arduino.getPin(2); + tmpPin = arduino.getPin(11); this.addPin(tmpPin); tmpPin.setObserver(this);